Solved

Print Problem

Posted on 2000-05-10
3
160 Views
Last Modified: 2010-04-04
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
Comment
Question by:ws1999
3 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2796415
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
 
LVL 5

Expert Comment

by:TheNeil
ID: 2804052
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
 

Accepted Solution

by:
SERENNE earned 100 total points
ID: 2806441
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now