Using GDI Functions in Print Processors

A set of user-mode GDI functions is exported by Gdi32.dll, for use by print processors that handle NT-based-operating system EMF as an input format. The following table lists the functions that are provided.

Function name Description
GdiDeleteSpoolFileHandle Releases a spool file handle.
GdiEndDocEMF Completes EMF playback operations for a print job document.
GdiEndPageEMF Completes EMF playback operations for a physical page, and ejects the page from the printer.
GdiGetDC Returns a handle to the printer's device context.
GdiGetDevmodeForPage Returns a document page's DEVMODEW structure.
GdiGetPageCount Returns the number of document pages.
GdiGetPageHandle Returns a handle to a document page.
GdiGetSpoolFileHandle Returns a spool file handle, required as input to the other GDI functions.
GdiPlayPageEMF Plays the EMF records associated with a document page.
GdiResetDCEMF Resets a printer's device context.
GdiStartDocEMF Performs initialization operations for the print job document.
GdiStartPageEMF Performs initialization operations for a physical page.

An EMF print processor's PrintDocumentOnPrintProcessor should call GdiGetSpoolFileHandle to obtain a spool file handle and GdiGetDC to obtain the printer's device context handle. Then it can perform the following steps:

  • For each print job document, GdiStartDocEMF must be called before any EMF records are played and GdiEndDocEMF must be called after the last EMF record has been played.

  • For each physical page to be printed, GdiStartPageEMF must be called before any document pages are drawn on the page, and GdiEndPageEMF must be called after the last document page has been drawn on the physical page.

  • For each document page to be drawn on a physical page, GdiGetDevmodeForPage must be called to determine if the DEVMODE structure contents have changed since the last document page was drawn. If the DEVMODE has changed, a new physical page must be started (by calling GdiEndPageEMF and GdiStartPageEMF), and the printer's device context must be updated by calling GdiResetDCEMF. A document page is drawn on a physical page by first calling GdiGetPageHandle to obtain a document page handle, and then calling GdiPlayPageEMF to draw the page.

After the job has been completely drawn, the print processor must call GdiDeleteSpoolFileHandle.

If a print processor requires the total page count before it can begin printing pages (such as for printing pages in reverse order) it can call GdiGetPageCount, but this function doesn't return until spooling ends and thus disables the ability to print while spooling.

If a print processor uses these GDI functions, its EnumPrintProcessorDatatypes function must return "NT EMF" as a supported data type, which represents generic Windows 2000 and later EMF format. The print processor must not modify EMF records.