Solved

Print Problem

Posted on 2000-05-10
3
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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