Using Printer Escapes w/PS Printers on Windows NT & Win32s

Last reviewed: September 29, 1995
Article ID: Q124135
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1, 3.5, and 3.51
        - Microsoft Win32s versions 1.1, 1.15, 1.15a, and 1.2
    

SUMMARY

To identify and print to PostScript printers from a Win32-based application under Windows NT and under Win32s, you need to special-case your code. This is because the printer drivers respond to different Printer Escapes under Windows NT and Windows/Win32s.

This article discusses how to identify and print to PostScript printers on both Windows NT and Win32s.

MORE INFORMATION

Identification

To identify the printer as a PostScript printer, use this code:

   int gPrCode = 0;  // Set according to platform.

   if( Win32s ) // Using the Win16 driver.
   {
      gPrCode = PASSTHROUGH;
      if((Escape(printerIC, GETTECHNOLOGY, NULL, NULL, (LPSTR)szTech) &&
         !lstrcmp(szTech, "PostScript")) &&
         Escape(printerIC, QUERYESCSUPPORT, sizeof(int),
            (LPSTR)gPrCode, NULL )
      {
      // The printer is PostScript.
         ...
      }
   }
   else // Using Win32 driver under Windows NT.
   {
      gPrCode = POSTSCRIPT_PASSTHROUGH; // Fails with Win16 driver
      if( Escape(printerIC, QUERYESCSUPPORT, sizeof(int), (LPSTR)gPrCode,
          NULL))
      {
      // The printer is PostScript.
         ...
      }
   }

Printing

To send PostScript data to the printer on either platform, use this code:

// Assuming a buffer, szPSBuf, of max size MAX_PSBUF containing
// nPSData bytes of PostScript data.

   char szBuf[MAX_PSBUF+sizeof(short)];

// Store length in buffer.
   *((short *)szBuf) = nPSData;

// Store data in buffer.
   memcpy( (char *)szBuf + sizeof(short), szPSBuf, nPSData );

// Note that gPrCode (set when identifying the printer) depends on
// the platform.
   Escape( printerDC, gPrCode, (int) nPSData, szBuf, NULL );

However, your output may appear scaled or translated incorrectly or data may be transformed off the page under Win32s.

The origin and scale for Windows printer drivers is not the PostScript default (bottom left/72 dpi) but is instead at the upper left and at the device scale(300 dpi). Therefore, before sending data to the printer, you may need to send a couple of PostScript commands to scale or translate the matrix. For example, for scaling, send the following escape to scale the PostScript transform to 72 dpi:

   xres = GetDeviceCaps(printerDC, LOGPIXELSX);
   yres = GetDeviceCaps(printerDC, LOGPIXELSY);

// Two leading spaces for the following operation.
   wsprintf(szBuf, "  %d 72 div %d 72 div scale\n", xres, yres);

// Put actual size into buffer
   *((short *)szBuf) = strlen(szBuf)-2;
   Escape( printerDC, gPrCode, strlen(szBuf)-2, szBuf, NULL );


Additional reference words: 1.10 1.20 3.10 3.50
KBCategory: kbprint kbcode
KBSubcategory: GdiPrn W32s


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.