Click here to Skip to main content
11,572,401 members (49,271 online)
Click here to Skip to main content

EMF Printer Spool File Viewer

, 23 Apr 2014 CPOL 440.7K 15.8K 82
Rate this:
Please Sign up or sign in to vote.
A viewer application for EMF format spool files.

What is an EMF spool file?

When an application sends pages to a printer they are held in an intermediary file which the application can write to and the printer driver can read from simultaneously. This speeds up the print process as 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 known as an EMF spool file.

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

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? 
    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.

Using the EMF spoolfile viewer

To view an EMF spool file, select the menu File -> Open. A dialog box will appear to allow 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.)

The viewer allows you to go to a particular page, zoom in and out, and even print the spool file using the following menu options:

  • File
    • Open - Brings up a dialog box to find and open EMF spool files.
    • Print - Allows you to reprint the currently open EMF spool file.
    • Properties - Brings up a dialog box listing the print file properties.
    • Exit - Quits the application.
  • Pages
    • First Page - Goes to the beginning of the document.
    • Previous Page - Goes back one page.
    • Next Page - Goes to the next page.
    • Last Page - Goes to the end of the document.
    • Goto - Goes directly to the selected page.
    • Properties = Brings up a dialog with the properties of this page.
  • View
    • Zoom in enlarges the preview.
    • Zoom out reduces the size of the preview.

Uses for EMF spoolfiles

Since pretty much every application has a print function, the EMF spool file can serve as a quick and dirty portable document format (though much less featured than a PDF). Thus if you have an application and you want to send a file to someone who doesn't have that application to view, 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 it is possible to parse the file to extract information from it. You might want to extract just the text from a printed document for archival purposes, and you can do this by parsing the file and extracting the EMR_EXTTEXTOUTA and EMR_EXTTEXTOUTW records.

Acknowledgements

The source code in this application draws heavily on the work of Feng Yuan and Christophe Lindemann as well as numerous others on the various forums and news groups.

Portions of this article based on www.undocprint.org/formats/winspool/spl. These portions are subject to the GNU Free Documentation License and are copyright © 2003-2005 Free Software Foundation, Inc.

History

  • 21 Aug 2006

    Code updated to .NET 2.0 and page navigation improved.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Duncan Edwards Jones
Software Developer (Senior)
Ireland Ireland
C# / SQL Server developer
Microsoft MVP 2006, 2007
Visual Basic .NET

You may also be interested in...

Comments and Discussions

 
GeneralProblem with HP Laserjet Pin
ademian4421-May-08 11:29
memberademian4421-May-08 11:29 
GeneralRe: Problem with HP Laserjet Pin
Duncan Edwards Jones21-May-08 11:50
memberDuncan Edwards Jones21-May-08 11:50 
GeneralEMF Spoolfile documentation update Pin
Duncan Edwards Jones8-May-08 23:46
memberDuncan Edwards Jones8-May-08 23:46 
GeneralPrint EMF spool File Pin
Efrain Dominguez Goycochea5-May-08 13:58
memberEfrain Dominguez Goycochea5-May-08 13:58 
GeneralRe: Print EMF spool File Pin
Duncan Edwards Jones9-May-08 1:35
memberDuncan Edwards Jones9-May-08 1:35 
GeneralRe: Print EMF spool File Pin
Efrain Dominguez Goycochea9-May-08 4:48
memberEfrain Dominguez Goycochea9-May-08 4:48 
GeneralRe: Print EMF spool File Pin
Efrain Dominguez Goycochea12-May-08 7:25
memberEfrain Dominguez Goycochea12-May-08 7:25 
GeneralRe: Print EMF spool File Pin
Duncan Edwards Jones13-May-08 1:25
memberDuncan Edwards Jones13-May-08 1:25 
GeneralRe: Print EMF spool File Pin
Efrain Dominguez Goycochea19-May-08 7:32
memberEfrain Dominguez Goycochea19-May-08 7:32 
QuestionPrinting? Pin
SkotePetoors1-Apr-08 4:33
memberSkotePetoors1-Apr-08 4:33 
AnswerRe: Printing? Pin
Duncan Edwards Jones9-May-08 1:32
memberDuncan Edwards Jones9-May-08 1:32 
GeneralCan´t open the EMF spool file Pin
Mariano Capezzani10-Mar-08 14:18
memberMariano Capezzani10-Mar-08 14:18 
GeneralRe: Can´t open the EMF spool file Pin
Duncan Edwards Jones11-Mar-08 18:33
memberDuncan Edwards Jones11-Mar-08 18:33 
GeneralRe: Can´t open the EMF spool file Pin
Mariano Capezzani12-Mar-08 2:20
memberMariano Capezzani12-Mar-08 2:20 
Thank you!

Now I see. I have to browse the file until I get a valid PAGE record and from there on I can either use GetEnhMetaFile(), o rather continue browsing manually the different record types.

I´ve just programmed this and it seems to work fine. Big Grin | :-D

However... I´ve found that some spool files have no EXT_TEXTTOUTA or EXT_TEXTOUTW records, but they DO have text in them, and they DO open ok with your application. And the text is not an image...

Can there be printable text contained in another type of record? I´ve found no documentation about this. Confused | :confused:

Regards,
GeneralRe: Can´t open the EMF spool file Pin
Mariano Capezzani12-Mar-08 9:45
memberMariano Capezzani12-Mar-08 9:45 
GeneralRe: Can´t open the EMF spool file Pin
Duncan Edwards Jones9-May-08 3:07
memberDuncan Edwards Jones9-May-08 3:07 
QuestionRe: Can´t open the EMF spool file Pin
Mariano Capezzani13-May-08 4:33
memberMariano Capezzani13-May-08 4:33 
GeneralRe: Can´t open the EMF spool file Pin
hsirc21-Sep-08 10:23
memberhsirc21-Sep-08 10:23 
GeneralPrinter Setup Pin
CycloneBoy13-Nov-07 9:00
memberCycloneBoy13-Nov-07 9:00 
QuestionDoes it support under dotNet 1.1? Pin
MKHA230-Oct-07 20:36
memberMKHA230-Oct-07 20:36 
QuestionSpool file name Pin
fflyw10-May-07 11:42
memberfflyw10-May-07 11:42 
AnswerRe: Spool file name Pin
Duncan Edwards Jones10-May-07 20:54
memberDuncan Edwards Jones10-May-07 20:54 
GeneralRe: Spool file name Pin
fflyw10-May-07 21:22
memberfflyw10-May-07 21:22 
GeneralRe: Spool file name Pin
fflyw10-May-07 21:24
memberfflyw10-May-07 21:24 
QuestionKeep printed documents Pin
fflyw1-May-07 10:29
memberfflyw1-May-07 10:29 
AnswerRe: Keep printed documents Pin
Duncan Edwards Jones1-May-07 10:59
memberDuncan Edwards Jones1-May-07 10:59 
QuestionWrong number of pages. Pin
Raphael Burgui28-Feb-07 8:13
memberRaphael Burgui28-Feb-07 8:13 
AnswerRe: Wrong number of pages. Pin
Duncan Edwards Jones1-Mar-07 21:18
memberDuncan Edwards Jones1-Mar-07 21:18 
GeneralRe: Wrong number of pages. Pin
Raphael Burgui1-Mar-07 23:55
memberRaphael Burgui1-Mar-07 23:55 
GeneralRe: Wrong number of pages. Pin
Duncan Edwards Jones2-Mar-07 3:31
memberDuncan Edwards Jones2-Mar-07 3:31 
QuestionEMF to PDF ?? Pin
Alexsander Antunes1-Feb-07 14:15
memberAlexsander Antunes1-Feb-07 14:15 
AnswerRe: EMF to PDF ?? Pin
Duncan Edwards Jones1-Feb-07 21:07
memberDuncan Edwards Jones1-Feb-07 21:07 
AnswerRe: EMF to PDF ?? Pin
Referee9812-Mar-07 5:09
memberReferee9812-Mar-07 5:09 
GeneralEMFSpoolFileReader - Device Not ready Pin
Andy Perry8-Aug-06 10:41
memberAndy Perry8-Aug-06 10:41 
GeneralRe: EMFSpoolFileReader - Device Not ready Pin
Duncan Edwards Jones8-Aug-06 11:30
memberDuncan Edwards Jones8-Aug-06 11:30 
GeneralRe: EMFSpoolFileReader - Device Not ready Pin
Andy Perry9-Aug-06 3:03
memberAndy Perry9-Aug-06 3:03 
GeneralRe: EMFSpoolFileReader - Device Not ready Pin
Andy Perry14-Aug-06 3:07
memberAndy Perry14-Aug-06 3:07 
GeneralRe: EMFSpoolFileReader - Device Not ready Pin
Duncan Edwards Jones4-Sep-06 4:03
memberDuncan Edwards Jones4-Sep-06 4:03 
GeneralSend Me VB6 Version Pin
Pacic_BIH23-Mar-06 11:57
memberPacic_BIH23-Mar-06 11:57 
GeneralRe: Send Me VB6 Version Pin
Duncan Edwards Jones23-Mar-06 20:53
memberDuncan Edwards Jones23-Mar-06 20:53 
QuestionTEXT and content ? Pin
semto8-Feb-06 1:05
membersemto8-Feb-06 1:05 
AnswerRe: TEXT and content ? Pin
Duncan Edwards Jones8-Feb-06 1:53
memberDuncan Edwards Jones8-Feb-06 1:53 
GeneralRe: TEXT and content ? Pin
semto8-Feb-06 2:01
membersemto8-Feb-06 2:01 
GeneralRe: TEXT and content ? Pin
Duncan Edwards Jones21-Aug-06 6:32
memberDuncan Edwards Jones21-Aug-06 6:32 
GeneralCan't run app Pin
joekuebler18-Jan-06 3:53
memberjoekuebler18-Jan-06 3:53 
GeneralRe: Can't run app Pin
Duncan Edwards Jones18-Jan-06 5:50
memberDuncan Edwards Jones18-Jan-06 5:50 
GeneralEMFSpoolfileReader Pin
rudi5556-Dec-05 3:48
memberrudi5556-Dec-05 3:48 
GeneralRe: EMFSpoolfileReader Pin
Duncan Edwards Jones6-Dec-05 23:04
memberDuncan Edwards Jones6-Dec-05 23:04 
GeneralRe: EMFSpoolfileReader Pin
rudi5557-Dec-05 2:53
memberrudi5557-Dec-05 2:53 
GeneralRe: EMFSpoolfileReader Pin
Tom Hellstrom14-Jan-06 3:25
memberTom Hellstrom14-Jan-06 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 23 Apr 2014
Article Copyright 2005 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid