Page 1 of 1

[TPrintPreview]Margin Of Printer

PostPosted: January 14th, 2004, 2:24 pm
by akeix
I'm French. Excuse-me for my english language.

How i can to have the margin minimun for to print with the component TPrintPreview ?

Thank You.

Akeix

PostPosted: January 14th, 2004, 3:16 pm
by Kambiz
PrintPreview does not have any method/property for this purpose.

Code: Select all
Offset.X := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
Offset.Y := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);

PostPosted: January 14th, 2004, 7:28 pm
by akeix
Ok

But, if the resolution of printer is different of the resolution of screen.

For example :
My printer = 300 DPI,
and my screen (and PrintPreview) = 72 DPI.

Thank you

Akeix

PostPosted: January 14th, 2004, 9:00 pm
by Kambiz
You can use ConvertUnits procedure for converting the values.

PostPosted: July 11th, 2004, 10:25 am
by aspence
This had me stumped for a bit too. To elaborate on the reply from Kambiz, I've written the following function:

Code: Select all
function GetPrintable: TRect;
begin
  with PrintPreview do
  begin
    result.Left   := ConvertUnits(GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX),
                     GetDeviceCaps(Printer.Handle, LOGPIXELSX),
                     mmPixel, Units);
    result.Top    := ConvertUnits(GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY),
                     GetDeviceCaps(Printer.Handle, LOGPIXELSY),
                     mmPixel, Units);
    result.Right  := result.Left + ConvertUnits(Printer.PageWidth,
                     GetDeviceCaps(Printer.Handle, LOGPIXELSX),
                     mmPixel, Units);
    result.Bottom := result.Top + ConvertUnits(Printer.PageHeight,
                     GetDeviceCaps(Printer.Handle, LOGPIXELSY),
                     mmPixel, Units);
  end;
end;


This code will handle cases where the printer x and y DPI are not the same. It will also handle cases where the printable area is not centered on the page (such as my printer, an Epson Stylus C60). Once you have the printable rectangle, all of your drawing to the preview should be kept within these boundaries. Incidentally, Printer.PageWidth and Printer.PageHeight represent the width and height of the printable area.

Since this code queries the printer itself, it's important that the printer settings reflect what is going on with the PrintPreview (your PrintPreview may be in Portrait mode when the printer is in landscape mode) so call PrintPreview.SetPrinterOptions before calling this function.

PostPosted: August 7th, 2004, 6:29 am
by akeix
Thank You !

PostPosted: December 19th, 2004, 10:23 pm
by Justino
PrintPreview.PrinterPageBounds Rect does the same for me.

Nice site, good components.

I'm having troubles with margins, but that's kinda normal when working with the printer. A lot of old printers can't even get the paper properly feeded. I'm starting to dislike programming printing stuff.. luckily you helped me making most part of the program. Thanks, from Holland.