Click here to Skip to main content
15,896,063 members
Articles / Web Development / HTML

EMF Printer Spool File Viewer

Rate me:
Please Sign up or sign in to vote.
4.72/5 (32 votes)
23 Apr 2014CPOL3 min read 816.9K   25.3K   92  
A viewer application for EMF format spool files
Imports System.IO
Imports System.Drawing

#Region "EMFMETAHEADER"
''' <summary>
''' The EMF header record for a spooled print job
''' </summary>
''' <remarks></remarks>
Public Class EMFMETAHEADER

#Region "Private properties"
    '\\ EMR record header
    Private _iType As Int32
    Private _nSize As Int32
    '\\ Boundary rectangle
    Private _rclBounds_Left As Int32
    Private _rclBounds_Top As Int32
    Private _rclBounds_Right As Int32
    Private _rclBounds_Bottom As Int32
    '\\ Frame rectangle
    Private _rclFrame_Left As Int32
    Private _rclFrame_Top As Int32
    Private _rclFrame_Right As Int32
    Private _rclFrame_Bottom As Int32
    '\\ "Signature"
    Private _signature_1 As Byte
    Private _signature_2 As Byte 'E
    Private _signature_3 As Byte 'M
    Private _signature_4 As Byte 'F
    '\\ nVersion
    Private _nVersion As UInt32
    Private _nBytes As Int32
    Private _nRecords As Int32
    Private _nHandles As Int32
    Private _sReversed As Int16
    Private _nDescription As Int16
    Private _offDescription As Int32
    Private _nPalEntries As Int32
    Private _szlDeviceWidth As Int32
    Private _szlDeviceHeight As Int32
    Private _szlDeviceWidthMilimeters As Int32
    Private _szlDeviceHeightMilimeters As Int32
    Private _cbPixelFormat As Int32
    Private _offPixelFormat As Int32
    Private _bOpenGL As Boolean
    Private _szlMicrometersWidth As Int32
    Private _szlMicrometersHeight As Int32
    Private _Description() As Char

#End Region

#Region "Public properties"
    ''' <summary>
    ''' The boundary of the printed page (the paper dimensions)
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property BoundaryRect() As Rectangle
        Get
            Return New Rectangle(_rclBounds_Left, _rclBounds_Top, _rclBounds_Right, _rclBounds_Bottom)
        End Get
    End Property

    ''' <summary>
    ''' The frame containing the print elements
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' This can be smaller than the paper size as many printers have a non-printable margin
    ''' around the edge of the page
    ''' </remarks>
    Public ReadOnly Property FrameRect() As Rectangle
        Get
            Return New Rectangle(_rclFrame_Left, _rclFrame_Top, _rclFrame_Right, _rclFrame_Bottom)
        End Get
    End Property

    Public ReadOnly Property Size() As Integer
        Get
            Return _nSize
        End Get
    End Property

    ''' <summary>
    ''' The number of EMF records that make up the printed page
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' These records describe teh text and graphical elements that make up the printed page
    ''' </remarks>
    Public ReadOnly Property RecordCount() As Integer
        Get
            Return _nRecords
        End Get
    End Property

    ''' <summary>
    ''' The size of the EMR file
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property FileSize() As Integer
        Get
            Return _nBytes
        End Get
    End Property

    ''' <summary>
    ''' The number of colours in the page's paletter
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property PalleteEntries() As Integer
        Get
            Return _nPalEntries
        End Get
    End Property

    ''' <summary>
    ''' The description text for this EMF spool record
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Description() As String
        Get
            Return _Description
        End Get
    End Property
#End Region

#Region "Public constructor"

    Public Sub New(ByVal SpoolBinaryReader As BinaryReader)

        Dim nStart As Long = SpoolBinaryReader.BaseStream.Position

        With SpoolBinaryReader
            _iType = .ReadInt32
            _nSize = .ReadInt32
            '\\ Boundary rectangle
            _rclBounds_Left = .ReadInt32
            _rclBounds_Top = .ReadInt32
            _rclBounds_Right = .ReadInt32
            _rclBounds_Bottom = .ReadInt32
            '\\ Frame rectangle
            _rclFrame_Left = .ReadInt32
            _rclFrame_Top = .ReadInt32
            _rclFrame_Right = .ReadInt32
            _rclFrame_Bottom = .ReadInt32
            '\\ "Signature"
            _signature_1 = .ReadByte
            _signature_2 = .ReadByte
            _signature_3 = .ReadByte
            _signature_4 = .ReadByte
            '\\ nVersion
            _nVersion = .ReadUInt32
            _nBytes = .ReadInt32
            _nRecords = .ReadInt32
            _nHandles = .ReadInt16
            _sReversed = .ReadInt16
            _nDescription = .ReadInt16
            Dim empty As Short = .ReadInt16
            _offDescription = .ReadInt32
            _nPalEntries = .ReadInt32
            _szlDeviceWidth = .ReadInt32
            _szlDeviceHeight = .ReadInt32
            _szlDeviceWidthMilimeters = .ReadInt32
            _szlDeviceHeightMilimeters = .ReadInt32
            If _nSize > 88 Then
                _cbPixelFormat = .ReadInt32
                _offPixelFormat = .ReadInt32
                _bOpenGL = .ReadBoolean
            End If
            If _nSize > 100 Then
                _szlMicrometersWidth = .ReadInt32
                _szlMicrometersHeight = .ReadInt32
            End If
            If _nDescription > 0 Then
                SpoolBinaryReader.BaseStream.Seek(nStart + _offDescription, SeekOrigin.Begin)
                _Description = .ReadChars(_nDescription)
            End If
        End With
    End Sub
#End Region

End Class
#End Region

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

Comments and Discussions