An EMF Spoolfile Viewer

What Is an EMF Spool File?

When an application sends pages to a printer, they are held in an intermediary file that the application can write to and the printer driver can read from simultaneously. This speeds up the print process because control can return to the application before the printer has finished printing the document.

Usually, this spool file is held in the raw printer page definition language (which could be PCL, PostScript, or one of many other options) but in Windows NT, 2000, XP, and 2003 it is possible to make the spooler use a different, more device-independent format knowns a an EMF spool file.

The file layout of an EMF spool file is not officially documented by Microsoft, but a bit of investigation reveals that it is a series of enhanced metafile records (one for each page) and a number of other record types that are specific to the business of printing these pages

To generate EMF spool files from Windows NT, 200, XP, and 2003, select the printer properties and on the scheduling tab select "Keep printed documents." This will create a .shd and .spl file for each document you print in your spool directory (usually C:\WINNT\system32\spool).

The EMF Spool File Record Types

The spool file is composed of the following record types:

Private Enum SpoolerRecordTypes
   SRT_EOF           = &H0       ' // int32 zero
   SRT_RESERVED_1    = &H1       '*  1                               */
   SRT_FONTDATA      = &H2       '   2 Font Data                     */
   SRT_DEVMODE       = &H3       '   3 DevMode                       */
   SRT_FONT2         = &H4       '   4 Font Data                     */
   SRT_RESERVED_5    = &H5       '   5                               */
   SRT_FONT_MM       = &H6       '   6 Font Data (Multiple Master)   */
   SRT_FONT_SUB1     = &H7       '   7 Font Data (SubsetFont 1)      */
   SRT_FONT_SUB2     = &H8       '   8 Font Data (SubsetFont 2)
   SRT_RESERVED_9    = &H9
   SRT_UNKNOWN       = &H10      ' // int unknown...
   SRT_RESERVED_A    = &HA
   SRT_RESERVED_B    = &HB
   SRT_PAGE          = &HC       ' 12  Enhanced Meta File (EMF)      */
   SRT_EOPAGE1       = &HD       ' 13  EndOfPage                     */
   SRT_EOPAGE2       = &HE       ' 14  EndOfPage                     */
   SRT_EXT_FONT      = &HF       ' 15  Ext Font Data                 */
   SRT_EXT_FONT2     = &H10      ' 16  Ext Font Data                 */
   SRT_EXT_FONT_MM   = &H11      ' 17  Ext Font Data (Multiple Master)
   SRT_EXT_FONT_SUB1 = &H12      ' 18  Ext Font Data (SubsetFont 1)  */
   SRT_EXT_FONT_SUB2 = &H13      '* 19  Ext Font Data (SubsetFont 2) */
   SRT_EXT_PAGE      = &H14      ' 20  Enhanced Meta File? 
   SRT_JOB_INFO      = &H10000   ' // int length, wchar jobDescription
End Enum

Of these, the most important record types are:

SRT_PAGE

This record contains a Windows standard enhanced metafile, consisting of an EMF header and one or more EMF graphics record structures. The EMF header record gives you the dimensions of the boundary rectangle (the area inside the print margins), the number of graphics records that make up the page, and the file size of this single EMF page.

SRT_DEVMODE

This record contains the device settings that apply to the rest of the pages in the document (or until another DEVMODE record is encountered that overrides it). The DEVMODE structure holds details such as the number of copies, the page orientation (landscape versus portrait), the paper size and paper source, and so on.

SRT_EOF

This signifies the end of the spool file records.

An EMF Spoolfile Viewer

Using the EMF Spoolfile Viewer

To view an EMF spool file, select the menu File -> Open. A dialog box will appear, allowing you to browse to the spool file (extension .spl). These are typically held in your $winnt$\System32\spool\ directory. (I have included some samples with this application code as well.)

Uses for EMF Spoolfiles

Because pretty much every application has a print function, the EMF spool file can serve as a quick and dirty portable document format. Thus, if you have an application and you want to send a file to someone who doesn't have that application to view it, you simply use the application's print function and send them the spool file.

In addition, knowing the structure of the spool file means that is possible to parse the file and extract information from it. You might want to extract just the text from a printed document for archival purposes; you can do this by parsing the file and extracting the EMR_EXTTEXTOUTA and EMR_EXTTEXTOUTW records.



About the Author

Duncan Jones

Freelance developer with 10 years experience in Visual basic and SQL - now moving on up to the next generation with .NET

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds