Solved

Print Problem

Posted on 2000-05-10
3
162 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 151
Delphi: how to implement a User Shortcut mapper? 1 107
control image tags in a string ? 12 129
SUM 2 INTEGER ARRAYS INTO 1 10 100
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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