Table of Contents

Class PdfDocument

Namespace
UglyToad.PdfPig
Assembly
UglyToad.PdfPig.dll

Provides access to document level information for this PDF document as well as access to the Pages contained in the document.

public class PdfDocument : IDisposable
Inheritance
PdfDocument
Implements
Inherited Members

Properties

Advanced

Access to rare or advanced features of the PDF specification.

public AdvancedPdfDocumentAccess Advanced { get; }

Property Value

AdvancedPdfDocumentAccess

Information

The metadata associated with this document.

public DocumentInformation Information { get; }

Property Value

DocumentInformation

IsEncrypted

Whether the document content is encrypted.

public bool IsEncrypted { get; }

Property Value

bool

NumberOfPages

Get the number of pages in this document.

public int NumberOfPages { get; }

Property Value

int

Structure

Access to the underlying raw structure of the document.

public Structure Structure { get; }

Property Value

Structure

Version

The version number of the PDF specification which this file conforms to, for example 1.4.

public decimal Version { get; }

Property Value

decimal

Methods

Dispose()

Dispose the PdfDocument and close any unmanaged resources.

public void Dispose()

GetPage(int)

Get the page with the specified page number (1 indexed).

public Page GetPage(int pageNumber)

Parameters

pageNumber int

The number of the page to return, this starts from 1.

Returns

Page

The page.

GetPages()

Gets all pages in this document in order.

public IEnumerable<Page> GetPages()

Returns

IEnumerable<Page>

Open(byte[], ParsingOptions)

Creates a PdfDocument for reading from the provided file bytes.

public static PdfDocument Open(byte[] fileBytes, ParsingOptions options = null)

Parameters

fileBytes byte[]

The bytes of the PDF file.

options ParsingOptions

Optional parameters controlling parsing.

Returns

PdfDocument

A PdfDocument providing access to the file contents.

Open(Stream, ParsingOptions)

Creates a PdfDocument for reading from the provided stream. The caller must manage disposing the stream. The created PdfDocument will not dispose the stream.

public static PdfDocument Open(Stream stream, ParsingOptions options = null)

Parameters

stream Stream

A stream of the file contents, this must support reading and seeking. The PdfDocument will not dispose of the provided stream.

options ParsingOptions

Optional parameters controlling parsing.

Returns

PdfDocument

A PdfDocument providing access to the file contents.

Open(string, ParsingOptions)

Opens a file and creates a PdfDocument for reading from the provided file path.

public static PdfDocument Open(string filePath, ParsingOptions options = null)

Parameters

filePath string

The full path to the file location of the PDF file.

options ParsingOptions

Optional parameters controlling parsing.

Returns

PdfDocument

A PdfDocument providing access to the file contents.

TryGetBookmarks(out Bookmarks)

Gets the bookmarks if this document contains some.

public bool TryGetBookmarks(out Bookmarks bookmarks)

Parameters

bookmarks Bookmarks

Returns

bool

Remarks

This will throw a ObjectDisposedException if called on a disposed PdfDocument.

TryGetForm(out AcroForm)

Gets the form if this document contains one.

public bool TryGetForm(out AcroForm form)

Parameters

form AcroForm

Returns

bool

An AcroForm from the document or null if not present.

Remarks

This will throw a ObjectDisposedException if called on a disposed PdfDocument.

TryGetXmpMetadata(out XmpMetadata)

Get the document level metadata if present. The metadata is XML in the (Extensible Metadata Platform) XMP format.

public bool TryGetXmpMetadata(out XmpMetadata metadata)

Parameters

metadata XmpMetadata

The metadata stream if it exists.

Returns

bool

true if the metadata is present, false otherwise.

Remarks

This will throw a ObjectDisposedException if called on a disposed PdfDocument.