Table of Contents

Class Document

Namespace
EvoPdf
Assembly
evohtmltopdf.dll

This class encapsulates a PDF document and can be used to create a new PDF document or to load an existing PDF document

[ClassInterface(ClassInterfaceType.AutoDual)]
public class Document
Inheritance
Document
Inherited Members

Constructors

Document()

Creates an empty PDF document object. New pages can be added to the document and new PDF elements can be added to document pages.

public Document()

Document(ColorProfile)

Creates a PDF document with a color profile.

public Document(ColorProfile colorProfile)

Parameters

colorProfile ColorProfile

The color profile to be used when creating the PDF document

Document(ColorSpace)

Creates a PDF document with the specified color space. This property can be used to create PDF documents in RGB, Grayscale or CMYK color spaces. By default the document uses the RGB color space.

public Document(ColorSpace colorSpace)

Parameters

colorSpace ColorSpace

The color space of the document.

Document(PdfStandardSubset)

Creates a PDF document based on the specified PDF standard. By default the Full PDF standard is used. This property can be used to create PDF/A or PDF/X compliant documents.

public Document(PdfStandardSubset pdfSubset)

Parameters

pdfSubset PdfStandardSubset

The PDF standard used to create the PDF document.

Document(PdfStandardSubset, ColorSpace)

Creates a PDF document based on the specified PDF standard and using the specified color space. By default the Full PDF standard is used. This property can be used to create PDF/A or PDF/X compliant documents using the specified color space.

public Document(PdfStandardSubset pdfSubset, ColorSpace colorSpace)

Parameters

pdfSubset PdfStandardSubset

The PDF standard used to create the PDF document.

colorSpace ColorSpace

The color space of the document.

Document(PdfStandardSubset, ColorSpace, ColorProfile)

Creates a PDF document based on the specified PDF standard and using the specified color space and color profile. By default the Full PDF standard is used. This property can be used to create PDF/A or PDF/X compliant documents using the specified color space.

public Document(PdfStandardSubset pdfSubset, ColorSpace colorSpace, ColorProfile colorProfile)

Parameters

pdfSubset PdfStandardSubset

The PDF standard used to create the PDF document.

colorSpace ColorSpace

The color space of the document.

colorProfile ColorProfile

The color profile to be used when creating the PDF document

Document(Stream)

Creates a PDF document object from the specified stream containing the PDF document.

public Document(Stream pdfStream)

Parameters

pdfStream Stream

The PDF document stream.

Document(Stream, string)

Creates a PDF document from a stream containing a password protected PDF document. The specified password can be a user or owner password.

public Document(Stream pdfStream, string password)

Parameters

pdfStream Stream

The stream containing the PDF document.

password string

The password to open the specified PDF document.

Document(string)

Creates a PDF document from and existing PDF file.

public Document(string pdfFilePath)

Parameters

pdfFilePath string

The full path of an existing PDF document file.

Document(string, string)

Creates a PDF document object from an existing password protected PDF file.

public Document(string pdfFilePath, string password)

Parameters

pdfFilePath string

The full path to the PDF file.

password string

The password to open the specified PDF document.

Properties

AutoCloseAppendedDocs

Gets or sets a value indicating if the PDF documents appended to this document using the AppendDocument(Document) method are automatically closed when the current document is closed using the Close() method. The default value is false. The appended documents must remain open until the current document is saved.

public bool AutoCloseAppendedDocs { get; set; }

Property Value

bool

Bookmarks

Gets the bookmarks collection of the document.

public BookmarksCollection Bookmarks { get; }

Property Value

BookmarksCollection

CompressCrossReference

Set this property on true to store the PDF cross-reference table and PDF trailer in compressed cross-reference streams and to reduce the PDF file size. The default value is false for the new documents

public bool CompressCrossReference { get; set; }

Property Value

bool

CompressionLevel

Gets or sets the PDF document compression level. By default the compression level is Normal

public PdfCompressionLevel CompressionLevel { get; set; }

Property Value

PdfCompressionLevel

DocumentInformation

Offers access to the document information object where the document's title, subject, keywords, etc can be set.

public DocumentInformation DocumentInformation { get; }

Property Value

DocumentInformation

Fonts

Gets the collection of fonts of this PDF document.

public FontCollection Fonts { get; }

Property Value

FontCollection

Represents the default PDF document footer template. This footer is automatically considered when calculating the available space for rendering in a PDF page. This template is automatically docked to the bottom of the PDF page.

public Template Footer { get; set; }

Property Value

Template

Form

Gets a reference to the PDF form of this PDF document

public PdfForm Form { get; }

Property Value

PdfForm

Header

Represents the default PDF document header template. This header is automatically considered when calculating the available space for drawing in a PDF page. This template is automatically docked to the top of the PDF page.

public Template Header { get; set; }

Property Value

Template

JpegCompressionEnabled

Gets or sets a flag indicating if the JPEG compression is enabled or not for the images in the generated PDF. By default the JPEG compression is enabled to reduce the size of the generated PDF. When the JPEG compression is enabled the quality of the images in the generated PDF is lower than the quality of the original images in the HTML document, function of the JpegCompressionLevel parameter. When the JpegCompressionLevel is increased, the quality of the images in PDF decreases.

public bool JpegCompressionEnabled { get; set; }

Property Value

bool

JpegCompressionLevel

Gets or sets the compression level of images in the generated PDF as an integer value between 0 and 100. This property has effect only when the JpegCompressionEnabled is true. When the JpegCompressionLevel is 0, the compression rate is the lowest and the quality of the images is the best. When the JpegCompressionLevel is 100, the compression rate is the highest and quality of the images in PDF is the worst. The default JPEG compression level is 10, which should offer a good balance between the compression rate and the quality of the images in PDF.

public int JpegCompressionLevel { get; set; }

Property Value

int

LicenseKey

Gets or sets the license key string received from the vendor. If this property is null the library will automatically enter in evaluation mode and a demo watermark will be displayed on the generated PDF document.

public string LicenseKey { get; set; }

Property Value

string

Margins

The default document margins. The new pages will use the default margins if no margins are specified

public Margins Margins { get; set; }

Property Value

Margins

OpenAction

The Go To, JavaScript, Submit Form or Reset Form action to be performed when the PDF document is opened.

public DocumentOpenAction OpenAction { get; }

Property Value

DocumentOpenAction

Pages

Gets the collection of pages of this PDF document.

public PageCollection Pages { get; }

Property Value

PageCollection

Security

Offers access to security features of the PDF document like encryption.

public Security Security { get; }

Property Value

Security

TableOfContents

Gets a reference to the object controlling the automatic creation of a table of contents in the generated PDF document based on HtmlToPdfElement and HtmlToImageElement objects added to PDF document

public PdfDocumentTableOfContents TableOfContents { get; }

Property Value

PdfDocumentTableOfContents

Templates

Gets the collection of templates of this PDF document.

public TemplateCollection Templates { get; }

Property Value

TemplateCollection

TransparencyEnabled

Gets or sets a flag indicating if the transparency is enabled in the PDF document. Default value is true. This property can be set to false to eliminate the additional flattening time when the document is sent to the printer from Adobe Reader viewer.

public bool TransparencyEnabled { get; set; }

Property Value

bool

ViewerPreferences

Offers access to the viewer preferences settings for the document.

public DocumentViewerPreferences ViewerPreferences { get; }

Property Value

DocumentViewerPreferences

Methods

AddBookmark(string, ExplicitDestination)

Creates a root bookmark for the document

public Bookmark AddBookmark(string text, ExplicitDestination destination)

Parameters

text string

The bookmark text

destination ExplicitDestination

The bookmark destination

Returns

Bookmark

The newly added bookmark.

AddBookmark(string, ExplicitDestination, Bookmark)

Creates a child bookmark for the existing parentBookmark

public Bookmark AddBookmark(string text, ExplicitDestination destination, Bookmark parentBookmark)

Parameters

text string

The text of the child bookmark

destination ExplicitDestination

The destination of the child bookmark

parentBookmark Bookmark

The parent bookmark

Returns

Bookmark

The newly added bookmark.

AddFileAttachment(Stream, string)

Adds an attachment with the given name from a stream to this PDF document

public void AddFileAttachment(Stream fileStream, string attachmentName)

Parameters

fileStream Stream

The file stream

attachmentName string

A name for attachment

AddFileAttachment(Stream, string, string)

Adds an attachment with the given name and a given description from a stream to this PDF document

public void AddFileAttachment(Stream fileStream, string attachmentName, string descr)

Parameters

fileStream Stream

The file stream

attachmentName string

A name for attachment

descr string

The attachment description

AddFileAttachment(string)

Adds an attachment a given file to this PDF document

public void AddFileAttachment(string filePath)

Parameters

filePath string

The path to file to be attached

AddFileAttachment(string, string)

Adds an attachment a given file and given description to this PDF document

public void AddFileAttachment(string filePath, string descr)

Parameters

filePath string

The path to file to be attached

descr string

The attachment description

AddFont(StandardCJKFont)

Adds a standard CJK font to the collection. If the font was already added the method returns the existing font.

public PdfFont AddFont(StandardCJKFont stdCJKFont)

Parameters

stdCJKFont StandardCJKFont

The standard CJK font to add to the document fonts collection.

Returns

PdfFont

The CJK font added to the collection.

AddFont(StdFontBaseFamily)

Adds a standard font to the fonts collection. If the font was already added the method returns the existing font.

public PdfFont AddFont(StdFontBaseFamily stdFont)

Parameters

stdFont StdFontBaseFamily

The standard font family.

Returns

PdfFont

The font added to the collection.

AddFont(byte[])

Adds a system font to the fonts collection. The font is created from the specified font data. If the font was already added the method returns the existing font.

public PdfFont AddFont(byte[] fontData)

Parameters

fontData byte[]

The data of the font to be added.

Returns

PdfFont

The font added to the collection.

AddFont(byte[], float, FontStyle)

Adds a system font to the fonts collection. The font is created from the specified font data with the specified style. If the font was already added the method returns the existing font.

public PdfFont AddFont(byte[] fontData, float fontSizePoints, FontStyle fontStyle)

Parameters

fontData byte[]

The data of the font to be added.

fontSizePoints float

The font size in points.

fontStyle FontStyle

The style of the font to be added.

Returns

PdfFont

The font added to the collection.

AddFont(Font)

Adds a system font to the fonts collection. If the font was already added the method returns the existing font. By default the font is embedded in the PDF document in order to support Unicode texts.

public PdfFont AddFont(Font font)

Parameters

font Font

The font to be added to the collection.

Returns

PdfFont

The font added to the collection.

AddFont(Font, bool)

Adds a system font to the fonts collection. If the font was already added the method returns the existing font. The embedFont property indicates if the added font will be embedded into the PDF document.

public PdfFont AddFont(Font font, bool embedFont)

Parameters

font Font

Font for adding.

embedFont bool

When true the font will be embedded in the PDF document.

Returns

PdfFont

The font added to the collection.

AddFont(string)

Adds a system font to the fonts collection. The font is created from the specified file. If the font was already added the method returns the existing font.

public PdfFont AddFont(string fontFilename)

Parameters

fontFilename string

The file name of the font to be added.

Returns

PdfFont

The font added to the collection.

AddFont(string, float, FontStyle)

Adds a system font to the fonts collection. The font is created from the specified file with the specified style. If the font was already added the method returns the existing font.

public PdfFont AddFont(string fontFilename, float fontSizePoints, FontStyle fontStyle)

Parameters

fontFilename string

The file name of the font to be added.

fontSizePoints float

The font size in points.

fontStyle FontStyle

The style of the font to be added.

Returns

PdfFont

The font added to the collection.

AddFooterTemplate(float)

Adds a footer with the given height to document

public Template AddFooterTemplate(float height)

Parameters

height float

The footer height

Returns

Template

The newly added footer template

AddHeaderTemplate(float)

Adds a header with the given height to document

public Template AddHeaderTemplate(float height)

Parameters

height float

The header height

Returns

Template

The newly added header template

AddPage()

Creates a new PDF page and adds it to the collection. If there is a previous page in the collection, the orientation and size are inherited from the that page otherwise a first page with the default A4 size and Portrait orientation is created. The page margins are inherited from the default document margins

public PdfPage AddPage()

Returns

PdfPage

The newly created PDF page

AddPage(Margins)

Creates a new PDF page and adds it to the collection. If there is a previous page in the collection, the orientation and size are inherited from the that page otherwise a first page with the default A4 size and Portrait orientation is created

public PdfPage AddPage(Margins pageMargins)

Parameters

pageMargins Margins

The PDF page margins

Returns

PdfPage

The newly created PDF page

AddPage(PdfPage)

Adds the specified page to the document pages collection. The page to be added is allowed to be from another document. The source document of the page to be added must remain opened until the current document is saved.

public void AddPage(PdfPage pdfPage)

Parameters

pdfPage PdfPage

The page to be added to the collection.

AddPage(PdfPageSize, Margins)

Creates a new PDF page and adds it to the collection. If there is a previous page in the collection, the page orientation is inherited from the that page otherwise a first page with the specified size and Portrait orientation is created

public PdfPage AddPage(PdfPageSize pageSize, Margins pageMargins)

Parameters

pageSize PdfPageSize

The page size in points

pageMargins Margins

The page margins in points

Returns

PdfPage

The newly created PDF page

AddPage(PdfPageSize, Margins, PdfPageOrientation)

Creates a new PDF page with the specified size, margins and orientation and adds it to the collection

public PdfPage AddPage(PdfPageSize pageSize, Margins pageMargins, PdfPageOrientation pageOrientation)

Parameters

pageSize PdfPageSize

The PDF page size in points

pageMargins Margins

The PDF page margins in points

pageOrientation PdfPageOrientation

The PDF page orientation

Returns

PdfPage

The newly created PDF page

AddTemplate(RectangleF)

Adds a new template with the specified bounds to the document templates collection.

public Template AddTemplate(RectangleF bounds)

Parameters

bounds RectangleF

The template element bounds

Returns

Template

The newly added template.

AddTemplate(float, float)

Adds a new template with the specified width and height to the document templates collection. The template location is top left corner of the page.

public Template AddTemplate(float width, float height)

Parameters

width float

The template width

height float

The template height

Returns

Template

The newly added template

AppendDocument(Document)

Appends the document given as parameter to the current document. The appended document must remain open until the current document is saved

public void AppendDocument(Document doc)

Parameters

doc Document

The document to be appended

AppendDocument(Document, bool, bool, bool)

Appends the document given as parameter to the current document and optionally applies the current document header and footer to the appended document pages if the appended document was loaded from an external file or stream

public void AppendDocument(Document doc, bool enableHeaderAndFooter, bool drawHeaderOnFirstPage, bool drawFooterOnFirstPage)

Parameters

doc Document

The document to be appended

enableHeaderAndFooter bool

A flag indicating if the header and footer of the current document are also applied to the appended document pages

drawHeaderOnFirstPage bool

A flag indicating if the header is drawn on first page of the appended document

drawFooterOnFirstPage bool

A flag indicating if the footer is drawn on first page of the appended document

AppendDocument(Document, int, int)

Appends a range of pages from the document given as parameter to the current document. The appended document must remain open until the current document is saved

public void AppendDocument(Document doc, int fromPageIndex, int pageCount)

Parameters

doc Document

The document to be appended

fromPageIndex int

The page index in appended PDF document from where to start copying the pages

pageCount int

The number of pages to append

AppendDocument(Document, int, int, bool, bool, bool)

Appends a range of pages from the document given as parameter to the current document and optionally applies the current document header and footer to the appended document pages if the appended document was loaded from an external file or stream

public void AppendDocument(Document doc, int fromPageIndex, int pageCount, bool enableHeaderAndFooter, bool drawHeaderOnFirstPage, bool drawFooterOnFirstPage)

Parameters

doc Document

The document to be appended

fromPageIndex int

The page index in appended PDF document from where to start copying the pages

pageCount int

The number of pages to append

enableHeaderAndFooter bool

A flag indicating if the header and footer of the current document are also applied to the appended document pages

drawHeaderOnFirstPage bool

A flag indicating if the header is drawn on first page of the appended document

drawFooterOnFirstPage bool

A flag indicating if the footer is drawn on first page of the appended document

Close()

Releases all the resources allocated by this PDF document. Always call this method after the document was saved. If the document was created from a stream or file, the stream will be closed if it was not explicitly detached by calling the DetachStream() before the document is closed.

public void Close()

DetachStream()

Call this method to detach the stream from which this document was created. When this method is called before calling Close(), the Close method will not close the detached stream.

public void DetachStream()

GetPageCount(Stream)

A fast method to obtain the page count of a PDF document from the given stream.

public static int GetPageCount(Stream pdfStream)

Parameters

pdfStream Stream

The stream containing the PDF document for which to get the page count.

Returns

int

The number of pages in the specified PDF document.

GetPageCount(string)

A fast method to obtain the page count of a PDF document from the given file path.

public static int GetPageCount(string pdfFilePath)

Parameters

pdfFilePath string

The path of the PDF file for which to get the page count.

Returns

int

The number of pages in the specified PDF document.

InsertDocument(int, Document)

Inserts the document given as parameter in the current document at the given page index. The appended document must remain open until the current document is saved

public void InsertDocument(int insertIndex, Document doc)

Parameters

insertIndex int

The page index where to start insertion in this document

doc Document

The document to be inserted

InsertDocument(int, Document, bool, bool, bool)

Inserts the document given as parameter to the current document and optionally applies the current document header and footer to the appended document pages if the appended document was loaded from an external file or stream

public void InsertDocument(int insertIndex, Document doc, bool enableHeaderAndFooter, bool drawHeaderOnFirstPage, bool drawFooterOnFirstPage)

Parameters

insertIndex int

The page index where to start insertion in this document

doc Document

The document to be appended

enableHeaderAndFooter bool

A flag indicating if the header and footer of the current document are also applied to the inserted document pages

drawHeaderOnFirstPage bool

A flag indicating if the header is drawn on first page of the inserted document

drawFooterOnFirstPage bool

A flag indicating if the footer is drawn on first page of the inserted document

InsertDocument(int, Document, int, int)

Inserts a range of pages from the document given as parameter in the current document at the given page index. The appended document must remain open until the current document is saved

public void InsertDocument(int insertIndex, Document doc, int fromPageIndex, int pageCount)

Parameters

insertIndex int

The page index where to start insertion in this document

doc Document

The document to be inserted

fromPageIndex int

The page index in appended PDF document from where to start copying the pages

pageCount int

The number of pages to insert

InsertDocument(int, Document, int, int, bool, bool, bool)

Inserts a range of pages from the document given as parameter to the current document and optionally applies the current document header and footer to the appended document pages if the appended document was loaded from an external file or stream

public void InsertDocument(int insertIndex, Document doc, int fromPageIndex, int pageCount, bool enableHeaderAndFooter, bool drawHeaderOnFirstPage, bool drawFooterOnFirstPage)

Parameters

insertIndex int

The page index where to start insertion in this document

doc Document

The document to be appended

fromPageIndex int

The page index in appended PDF document from where to start copying the pages

pageCount int

The number of pages to insert

enableHeaderAndFooter bool

A flag indicating if the header and footer of the current document are also applied to the inserted document pages

drawHeaderOnFirstPage bool

A flag indicating if the header is drawn on first page of the inserted document

drawFooterOnFirstPage bool

A flag indicating if the footer is drawn on first page of the inserted document

InsertPage(int, PdfPage)

Inserts the specified page into the document pages collection given by the Pages property at the specified index. The page to be added is allowed to be from another document. The source document of the page to be inserted must remain opened until the current document is saved.

public void InsertPage(int pageIndex, PdfPage pdfPage)

Parameters

pageIndex int

The index where the page will be inserted.

pdfPage PdfPage

The PDF page to be inserted.

InsertPage(int, PdfPageSize, Margins, PdfPageOrientation)

Creates a new PDF page with the specified size, margins and orientation and inserts it into the collection at the specified index.

public PdfPage InsertPage(int index, PdfPageSize pageSize, Margins pageMargins, PdfPageOrientation pageOrientation)

Parameters

index int

The index where to insert the new page.

pageSize PdfPageSize

The PDF page size in points

pageMargins Margins

The PDF page margins in points

pageOrientation PdfPageOrientation

The PDF page orientation

Returns

PdfPage

The newly created PDF page

RemovePage(PdfPage)

Removes the specified PDF page from the pages collection of this document.

public void RemovePage(PdfPage pdfPage)

Parameters

pdfPage PdfPage

The PDF page to be removed.

RemovePage(int)

Removes the PDF page at the specified index in pages collection.

public void RemovePage(int pageIndex)

Parameters

pageIndex int

The zero based index of the PDF page to be removed.

Save()

Saves the PDF document as byte array that can be further saved into a file or sent over HTTP to a browser.

public byte[] Save()

Returns

byte[]

The byte array representation of the document.

Save(Stream)

Saves this PDF document into the specified output stream.

public void Save(Stream outStream)

Parameters

outStream Stream

The stream where to save the PDF document.

Save(string)

Saves this PDF document into the file given by the method parameter

public void Save(string pdfFilePath)

Parameters

pdfFilePath string

The name of the file where to save the document. It can be a full path or a relative path.

Events

ExternalPdfPageAddedEvent

The event is raised after a page from an external PDF document is added to this document

public event ExternalPdfPageAddedDelegate ExternalPdfPageAddedEvent

Event Type

ExternalPdfPageAddedDelegate