Solved

Print Problem

Posted on 2000-05-10
3
159 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now