Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Detecting what direction a printer will rotate for a portrait


Some printers seems to rotate the portrait orientation to achieve a landscape page differently than others. This seems to affect the direction of a rotated font. How can I tell what direction a printer will rotate output on a landscape page, and if landscape mode is available on a given printer?   

    The following example demonstrates how to call the Windows API function DeviceCapabilities(), to find out how a portrait page is rotated to achieve a landscape page, enabling you to adjust your output accordingly. Generally, a print driver will rotate a landscape page either 90 degrees, or 270 degrees from its portrait orientation. Example:

    uses Printers;
    {$IFDEF WIN32}
    function DeviceCapabilitiesA(pDevice : PAnsiChar;
                                 pPort : PAnsiChar;
                                 fwCapability : Word;
                                 pOutput : PAnsiChar;
                                 DevMode : PDeviceModeA): Integer stdcall;
      external 'winspool.drv' name 'DeviceCapabilitiesA';
    function DeviceCapabilitiesW(pDevice : PWideChar;
                                 pPort : PWideChar;
                                 fwCapability: Word;
                                 pOutput: PWideChar;
                                 DevMode: PDeviceModeW): Integer stdcall;
      external 'winspool.drv' name 'DeviceCapabilitiesW';
    function DeviceCapabilities(pDevice : PChar;
                                pPort : PChar;
                                fwCapability : Word;
                                pOutput : PChar;
                                DevMode: PDeviceMode): Integer stdcall
      external 'winspool.drv' name 'DeviceCapabilitiesA';
    {$ENDIF}
    procedure TForm .Button Click(Sender: TObject);
    var
      Device : array[0..255] of char;
      Driver : array[0..255] of char;
      Port   : array[0..255] of char;
      hDMode : THandle;
      Rotation : integer;
    begin
      if PrintDialog .Execute then begin
       {Reset the printer}
        Printer.PrinterIndex := Printer.PrinterIndex;
        Printer.GetPrinter(Device, Driver, Port, hDMode);
        Rotation :=
          DeviceCapabilities(Device,
                             Port,
                             DC_ORIENTATION,
                             nil,
                             nil);
        case Rotation of
         0 :  ShowMessage('This device does not ' +
                          'support landscape');
         90 :  ShowMessage('This device rotates the portrait ' +
                          'orientation 90 degrees ' +
                          'to support landscape');
         270 :  ShowMessage('This device rotates the portrait ' +
                            'orientation 270 degrees ' +
                            'to support landscape');
        end;
      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