First some comments, next some code.
1) I'm testing my code on 4 printers (Samsung ML-1520, HP LaserJet 1010,
OkiPage 14ex, Canon PiXMA i2000), three of them laser printers, one ink jet.
They all give different results for the very same code (in terms of
positioning, the resulting rectangle is acceptably sized on all of them)
2) The formula I'm using for computing x/y dimensions is the one that gives
the best results (again, in terms of the resulting rectangle, ignoring it's
position in page). I also tested using LOGPIXELSX / LOGPIXELSY and found
those values are rounded and provide really bad results.
3) I tested my drawings using Corel Draw (to see if I can get a better 10x10
cm rectangle OR I can better position it). The result was comparable to
mine - good dimensions, bad position.
4) I ran a test using Ms WORD: I wrote some text and printed the page on all
printers. The text came out the same size on all printers BUT not in the
same place!
5) I'm not looking for a 100% solution. I'd be very happy if 90% of my users
would be able to use my program "out of the box" - without fiddeling with
margin settings.
<code>
procedure DemoPrint;
var x_unit:Integer;
y_unit:Integer;
offset_x:Integer;
offset_y:Integer;
res, size:Integer;
R:TRect;
begin
Printer.BeginDoc;
try
// I'll first read the printer's physical offset on both
// axes
offset_x := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
offset_y := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
// Next I'll compute the number of pixel that make up
// one centimeter (10 milimiters) on the X axes
res := GetDeviceCaps(Printer.Handle, HORZRES);
size := GetDeviceCaps(Printer.Handle, HORZSIZE);
x_unit := (res * 10) div size;
// Sam calculation on the Y axes (I'm not assuming equal pixel
// density on both axes)
res := GetDeviceCaps(Printer.Handle, VERTRES);
size := GetDeviceCaps(Printer.Handle, VERTSIZE);
y_unit := (res * 10) div size;
// I'll next print a 10x10 cm rectangle, 2 cm from the left of the
// page and 2 cm from the top of the page
R.Left := x_unit * 2 - offset_x;
R.Top := y_unit * 2 - offset_y;
R.Right := R.Left + x_unit * 10;
R.Bottom := R.Top + y_unit * 10;
Printer.Canvas.Rectangle(R);
finally Printer.EndDoc;
end;
end;
</code>
----- Original Message -----
From: "Stephen Posey" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Thursday, June 16, 2005 6:32 PM
Subject: Re: Paper margin
Cosmin Prund wrote:
I'm working on a program that prints on pre-printed forms and I'm having
lots of trouble figuring out paper margins. It seems the GetDeviceCaps
API gives the wrong results for the PHYSICALOFFSETX / PHYSICALOFFSETY
parameters.
Is there a way to find the ACTUAL offset for a given printer in any
real-world coordinate system? Knowing my application will mostly be used
on HP printers, is there a way to find this using something like HP PCL
or similar? Anything other then printing something and measuring white
bands is acceptable!
Before we get too far afield, how about posting some code for how you're
making your position calculations?
I find it's real easy to get confused about the meaning of what some of
the different GetDeviceCaps() Indicies refer to; not to mention adding
everything up and keeping it all oriented correctly.
Sometimes another pair of eyes...
Stephen Posey
[EMAIL PROTECTED]
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi