[TPrintPreview]Margin Of Printer

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

[TPrintPreview]Margin Of Printer

Postby akeix » January 14th, 2004, 2:24 pm

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
akeix
Active Member
Active Member
 
Posts: 7
Joined: January 14th, 2004, 2:12 pm
Location: France

Postby Kambiz » January 14th, 2004, 3:16 pm

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);
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

Postby akeix » January 14th, 2004, 7:28 pm

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
akeix
Active Member
Active Member
 
Posts: 7
Joined: January 14th, 2004, 2:12 pm
Location: France

Postby Kambiz » January 14th, 2004, 9:00 pm

You can use ConvertUnits procedure for converting the values.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

Postby aspence » July 11th, 2004, 10:25 am

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.
- Arnold B. Spence
aspence
Active Member
Active Member
 
Posts: 13
Joined: July 11th, 2004, 8:50 am
Location: Wolfville, N.S. Canada

Postby akeix » August 7th, 2004, 6:29 am

Thank You !
akeix
Active Member
Active Member
 
Posts: 7
Joined: January 14th, 2004, 2:12 pm
Location: France

Postby Justino » December 19th, 2004, 10:23 pm

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.
Justino
Member
Member
 
Posts: 1
Joined: December 19th, 2004, 10:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron