Click here to Skip to main content
13,346,664 members (23,058 online)
Click here to Skip to main content
Add your own
alternative version


88 bookmarked
Posted 3 Jun 2005

EMF Printer Spool File Viewer

, 23 Apr 2014
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 the newly released documentation ( 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_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:


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.


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.


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.


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 These portions are subject to the GNU Free Documentation License and are copyright © 2003-2005 Free Software Foundation, Inc.


  • 21 Aug 2006

    Code updated to .NET 2.0 and page navigation improved.


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
Software Developer (Senior)
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

You may also be interested in...


Comments and Discussions

GeneralA brief note about fonts Pin
Merrion19-Aug-05 7:59
memberMerrion19-Aug-05 7:59 
Generalcatch spool files Pin
mel999930-Jul-05 5:58
membermel999930-Jul-05 5:58 
GeneralRe: catch spool files Pin
Merrion1-Aug-05 8:41
memberMerrion1-Aug-05 8:41 
GeneralCan't run app Pin
T Akin16-Jul-05 13:19
sussT Akin16-Jul-05 13:19 
GeneralRe: Can't run app Pin
Merrion16-Jul-05 13:28
memberMerrion16-Jul-05 13:28 
Questionwhat kind of driver can the viewer see the spoole file? Pin
wanylee6-Jul-05 16:30
memberwanylee6-Jul-05 16:30 
AnswerRe: what kind of driver can the viewer see the spoole file? Pin
Merrion11-Jul-05 8:41
memberMerrion11-Jul-05 8:41 
Questionwhy can I not find a majority of items you said? Pin
seaiam23-Jun-05 17:27
memberseaiam23-Jun-05 17:27 
Hi Merrion, this is a great job,
but, why can I not find a majority of items you said? I use c++(VC6) write two functions to get all record type of a EMF spooler file, but I only get "SRT_DEVMODE" ,"SRT_PAGE" , "SRT_EOPAGE1", "SRT_EOPAGE2", and the number of "SRT_EOPAGE1"and "SRT_EOPAGE2" are wrong,
are there wrong in my code?

I check it by your sample(00002.spl) in your download file, result and code as follows:

Unknown number b8e8 0
Sum 22 Commands
Command EMF Record Type 25 sum 226
Command EMF Record Type 1b sum 1
Command EMF Record Type d sum 106
Command EMF Record Type 62 sum 1
Command EMF Record Type 64 sum 1
Command EMF Record Type 77 sum 1
Command EMF Record Type 16 sum 2
Command EMF Record Type 12 sum 49
Command EMF Record Type c sum 1
Command EMF Record Type 52 sum 21
Command EMF Record Type 18 sum 1
Command EMF Record Type 54 sum 215
Command EMF Record Type 28 sum 15
Command EMF Record Type 21 sum 10
Command EMF Record Type 1e sum 10
Command EMF Record Type 27 sum 6
Command EMF Record Type 4c sum 56
Command EMF Record Type 22 sum 10
Command EMF Record Type e sum 1
Command EMF Record Type 3 sum 1
Command EMF Record Type 0 sum 1
Command Unknown number sum 1

#define COMMND_MAX_NUM 200
#define USER_EMR_MAX 128
typedef struct stESCCommand
char szCommand[64];
char szExplain[64];
int nCounts;
/* ransack EMF spooler file, record different record type into a file */
if(pOUTFile == NULL || pINFile == NULL)
return false;
ZeroMemory(&emr, sizeof(ENHMETARECORD));
if(!fread(&emr, sizeof(DWORD), 2, pINFile))
return false;
if(emr.iType != 0x10000)
return false;
fseek(pINFile, emr.nSize, SEEK_CUR);

int nSize = sizeof(ENHMETAHEADER);
ZeroMemory(&emfHeader, nSize);
if(!fread(&emfHeader, sizeof(DWORD), 2, pINFile))
return false;
if(emfHeader.iType != 1)
return false;
fseek(pINFile, -8, SEEK_CUR);
if(!fread(&emfHeader, nSize, 1, pINFile))
return false;
fseek(pINFile, emfHeader.nSize-nSize, SEEK_CUR);
ZeroMemory(&emr, sizeof(ENHMETARECORD));
char szCommand[100];
while(fread(&emr, sizeof(DWORD), 2, pINFile))
if(emr.iType>=0&&emr.iType<=USER_EMR_MAX)//USER_EMR_MAX = 128
sprintf(szCommand, "%s\t%x", "EMF Record Type",emr.iType);
fseek(pINFile, emr.nSize-8, SEEK_CUR);
ZeroMemory(szCommand, sizeof(char)*100);
AddCommand("Unknown number");
fprintf(pOUTFile, "Unknown number %x\t\t%x\n", emr.iType, emr.nSize);
ZeroMemory(&emr, sizeof(ENHMETARECORD));
int nIndx=0;
fprintf(pOUTFile,"Sum %d Commands\n", m_nEntryIndex);
fprintf(pOUTFile, "Command %s\tsum %d\n", m_stESCCmmd[nIndx].szCommand,m_stESCCmmd[nIndx].nCounts);
ZeroMemory(m_stESCCmmd, sizeof(ESCCOMMAND)*COMMND_MAX_NUM);
m_nEntryIndex = 0;
return true;
/* add new record type into buffer*/
inline void CESC::AddCommand(LPCSTR lpszCommand, LPCSTR lpszExplain)
int nIndx=0;
bool boExist=false;
if(strncmp(m_stESCCmmd[nIndx].szCommand, lpszCommand, lstrlen(m_stESCCmmd[nIndx].szCommand))==0)
strncpy(m_stESCCmmd[m_nEntryIndex].szCommand, lpszCommand,ARRY_LENGTH);
strcpy(m_stESCCmmd[m_nEntryIndex].szExplain, lpszExplain);

AnswerRe: why can I not find a majority of items you said? Pin
Anonymous27-Jun-05 20:23
sussAnonymous27-Jun-05 20:23 
QuestionVB????? Pin
FireEmissary5-Jun-05 16:46
memberFireEmissary5-Jun-05 16:46 
AnswerRe: VB????? Pin
Christian Graus5-Jun-05 17:10
memberChristian Graus5-Jun-05 17:10 
GeneralRe: VB????? Pin
Merrion6-Jun-05 23:55
memberMerrion6-Jun-05 23:55 
QuestionDownloads don't work? Pin
RedZenBird3-Jun-05 19:05
memberRedZenBird3-Jun-05 19:05 
AnswerRe: Downloads don't work? Pin
Merrion4-Jun-05 0:17
memberMerrion4-Jun-05 0:17 
GeneralUseful and informative. Pin
Shog93-Jun-05 7:15
memberShog93-Jun-05 7:15 

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

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

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