5,276,156 members and growing! (21,535 online)
Email Password   helpLost your password?
Desktop Development » Printing » General     Intermediate License: The Code Project Open License (CPOL)

EMF Printer Spool File Viewer

By Duncan Edwards Jones

A viewer application for EMF format spool files.
C++, VBWindows, .NET, .NET 1.0, .NET 1.1, .NET 2.0, NT4, Win2K, WinXP, Win2003, GDI+, VS.NET2002, VS, Dev

Posted: 3 Jun 2005
Updated: 21 Aug 2006
Views: 93,427
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
14 votes for this Article.
Popularity: 4.70 Rating: 4.10 out of 5
0 votes, 0.0%
1
1 vote, 7.1%
2
0 votes, 0.0%
3
6 votes, 42.9%
4
7 votes, 50.0%
5

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)

About the Author

Duncan Edwards Jones


Microsoft MVP 2006, 2007
Visual Basic .NET
Occupation: Software Developer (Senior)
Location: Ireland Ireland

Other popular Printing articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 75 (Total in Forum: 75) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralProblem with HP Laserjetmemberademian4412:29 21 May '08  
GeneralRe: Problem with HP LaserjetmemberDuncan Edwards Jones12:50 21 May '08  
GeneralEMF Spoolfile documentation updatememberDuncan Edwards Jones0:46 9 May '08  
GeneralPrint EMF spool FilememberEfrain Dominguez Goycochea14:58 5 May '08  
GeneralRe: Print EMF spool FilememberDuncan Edwards Jones2:35 9 May '08  
GeneralRe: Print EMF spool FilememberEfrain Dominguez Goycochea5:48 9 May '08  
GeneralRe: Print EMF spool FilememberEfrain Dominguez Goycochea8:25 12 May '08  
GeneralRe: Print EMF spool FilememberDuncan Edwards Jones2:25 13 May '08  
GeneralRe: Print EMF spool FilememberEfrain Dominguez Goycochea8:32 19 May '08  
QuestionPrinting?memberSkotePetoors5:33 1 Apr '08  
AnswerRe: Printing?memberDuncan Edwards Jones2:32 9 May '08  
GeneralCan´t open the EMF spool filememberMariano Capezzani15:18 10 Mar '08  
GeneralRe: Can´t open the EMF spool filememberDuncan Edwards Jones19:33 11 Mar '08  
GeneralRe: Can´t open the EMF spool filememberMariano Capezzani3:20 12 Mar '08  
GeneralRe: Can´t open the EMF spool filememberMariano Capezzani10:45 12 Mar '08  
GeneralRe: Can´t open the EMF spool filememberDuncan Edwards Jones4:07 9 May '08  
QuestionRe: Can´t open the EMF spool filememberMariano Capezzani5:33 13 May '08  
GeneralPrinter SetupmemberCycloneBoy10:00 13 Nov '07  
GeneralDoes it support under dotNet 1.1?memberMKHA221:36 30 Oct '07  
QuestionSpool file namememberfflyw12:42 10 May '07  
AnswerRe: Spool file namememberDuncan Edwards Jones21:54 10 May '07  
GeneralRe: Spool file namememberfflyw22:22 10 May '07  
GeneralRe: Spool file namememberfflyw22:24 10 May '07  
QuestionKeep printed documentsmemberfflyw11:29 1 May '07  
AnswerRe: Keep printed documentsmemberDuncan Edwards Jones11:59 1 May '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Aug 2006
Editor: Chris Maunder
Copyright 2005 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project