Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

Print Problem

I want to print out a bitmap and some text(code as follows),but if the computer installed more than one printer,and I selected different printers to test printing,the result of printing will be different,sometimes the bitmap is big and sometimes small. I wonder what's the problem exists.

if (PrintDialog1.Execute) then
        begin
         Printer.BeginDOC;
         Printer.Canvas.TextOut(1000,100,'Headlines');
         DrawImage(Printer.Canvas,Rect(Left,400,Bmp_Width+Left,Bmp_Height+500),Image1.Picture.Bitmap);
         Printer.Canvas.Font.Size:=15;
          for i:= 0 to Part_Count-1 do
              Begin
          Printer.Canvas.Textout(600,800+Bmp_Height+i*100,Part_Name[i]);
          Printer.Canvas.Textout(1400,800+Bmp_Height+i*100,Current_Colors_Name[i]);
              End;
         Printer.EndDOC;
        end;
0
ws1999
Asked:
ws1999
1 Solution
 
LischkeCommented:
The result of the print depends on the printer's resolution. This is the number of points it can print in a certain area. This resolution is often given in DPI (dots per inch). Cheaper printers support only 300 dpi, while good laser printers can do 600, 800 or even more.

Since you are giving pixels it is clear that the same amount of pixels takes more or less room on different resolutions.

Ciao, Mike
0
 
TheNeilCommented:
Mike is right and to solve your problem use Stretchdraw and then base the parameters for it on the dimensions of the page.

rW := Printer.PageWidth / bmp.Width;
rH := Printer.PageHeight / bmp.Height;

IF rW > rH
THEN
  rW := rH
ELSE
  rH := rW;

iWidth := ROUND(bmp.Width * rW);  
iHeight := ROUND(bmp.Height * rH);

Printer.Canvas.StretchDraw(RECT(0, 0, iWidth, iHeight), bmp);


The Neil =:)
0
 
SERENNECommented:
To solve the problem, you must use the printer resolution where you want to print. Here are my routines to do this :


// x scale convertion: Vertpix in dpi, Value in 0,01 mm
// result in printer dots
function x(VertPix:integer;Value:Integer):Integer;
begin
     Result:=Trunc(Value*(VertPix /254));
end;

// y scale convertion:  Horzpix in dpi, Value in 0,01 mm
// result in printer dots
function y(HorzPix:integer;Value:Integer):Integer;
begin
     Result:=Trunc(Value*(HorzPix /254));
end;


// print and adjust with printer resolution
procedure MyForm.Print;
var
    VertPix,HorzPix:integer;

if (PrintDialog1.Execute) then
begin
       // Get then printer resolution in Dpi
       VertPix:=GetDeviceCaps(Printer.Handle,LOGPIXELSY);
       HorzPix:=GetDeviceCaps(Printer.Handle,LOGPIXELSX);

       Printer.BeginDOC;
       Printer.Canvas.TextOut(x(HorzPix,1000),y(VertPix,100),'Headlines');
DrawImage(Printer.Canvas,Rect(Left,400,x(HorzPix,Bmp_Width+Left),y(VertPix,Bmp_Height+500)),Image1.Picture.Bitmap);
       Printer.Canvas.Font.Size:=15;
       for i:= 0 to Part_Count-1 do
       Begin
   Printer.Canvas.Textout(x(HorzPix,600),y(HorzPix,800+Bmp_Height+i*100),Part_Name[i]);
                                  Printer.Canvas.Textout(x(HorzPix,1400),y(VertPix,800+Bmp_Height+i*100),Current_Colors_Name[i]);
       End;
      Printer.EndDOC;
end;

The print result will be the same on different printers.
Enjoy!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now