ID: Q124135
The information in this article applies to:
- Microsoft Windows NT versions 3.1, 3.5, and 3.51
- Microsoft Win32s versions 1.1, 1.15, 1.15a, and 1.2
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.
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.
...
}
}
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
Last Reviewed: July 7, 1999