Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Getting the printing margin of the page


How can I get the printing margin of the page?   

    Under Win 6, call the Windows API function Escape(), passing the constant GETPRINTINGOFFSET. Under Win32, simply call the Windows API function GetDeviceCaps() passing the predefined constants PHYSICALOFFSETX and PHYSICALOFFSETY. Since there is no guarantee a given escape is supported, always call Escape with the QUERYESCSUPPORT constant to make sure a given escape is implemented. The following example returns the margin of a given printer under both WIN 6 and WIN32, accounting for the fact that not all printers will support the escape code GETPRINTINGOFFSET (under WIN 6). If this is the case, the printing offset is approximated by getting the page size, subtracting the physical resolution of the device, and then diving by two. Example:

    uses Printers;
    procedure TForm .Button Click(Sender: TObject);
    var
      EscapeCode : integer;
      Margin : TPoint;
    begin
      if PrintDialog .Execute then begin
       {$IFDEF WIN32}
        Margin.x :=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
        Margin.y :=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
       {$ELSE}
        EscapeCode := GETPRINTINGOFFSET;
        if Escape(Printer.Handle,
                  QUERYESCSUPPORT,
                  sizeof(EscapeCode),
                  @EscapeCode,
                  nil) <> 0 then
          if Escape(Printer.Handle,
                    GETPRINTINGOFFSET,
                    0,
                    nil,
                    @Margin) <    then begin
           EscapeCode := GETPHYSPAGESIZE;
           if Escape(Printer.Handle,
                     QUERYESCSUPPORT,
                     sizeof(EscapeCode),
                     @EscapeCode,
                     nil) <> 0 then
            if Escape(Printer.Handle,
                      GETPHYSPAGESIZE,
                      0,
                      nil,
                      @Margin) > 0  then begin
              Margin.x := (Margin.x -
                           GetDeviceCaps(Printer.Handle, HorzRes)) div 2;
              Margin.y := (Margin.y -
                           GetDeviceCaps(Printer.Handle, VertRes)) div 2;
            end else begin
              Margin.x := 0;
              Margin.y := 0;
            end;
          end;
       {$ENDIF}
        Memo .Lines.Add(IntToStr(Margin.x));
        Memo .Lines.Add(IntToStr(Margin.y));
      end;
    end;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use