Table of Contents

Class PdfVectorDocument

Namespace
PdfEngine.Vector.Document
Assembly
PdfEngine.Vector.dll

Vector-first PDF document implementation conforming to IPdfVectorDocument.

public sealed class PdfVectorDocument : IPdfVectorDocument, IPdfDocument, IAsyncDisposable, IDisposable
Inheritance
PdfVectorDocument
Implements
Inherited Members

Properties

Catalog

The document catalog (/Root).

public PdfDictionary Catalog { get; }

Property Value

PdfDictionary

FilePath

The path the document was opened from; for a document opened from memory, the name given at open time.

public string FilePath { get; }

Property Value

string

HeaderVersion

The version in the file header ("%PDF-1.7" gives "1.7"), or null when the header has none.

public string? HeaderVersion { get; }

Property Value

string

HiddenAnnotations

The annotations (by object number) the screen display lists leave out.

public IReadOnlySet<int> HiddenAnnotations { get; }

Property Value

IReadOnlySet<int>

IsEncrypted

True when the file is encrypted (and was opened with a valid password).

public bool IsEncrypted { get; }

Property Value

bool

IsOpen

False after the document is disposed.

public bool IsOpen { get; }

Property Value

bool

Metadata

The document information and permissions read at open time.

public DocumentMetadata Metadata { get; }

Property Value

DocumentMetadata

PageCount

The number of pages.

public int PageCount { get; }

Property Value

int

PageTree

The flattened page tree (low-level access).

public PdfPageTree PageTree { get; }

Property Value

PdfPageTree

Resolver

Resolves indirect objects of the file (low-level access).

public PdfObjectResolver Resolver { get; }

Property Value

PdfObjectResolver

Security

The Standard security handler of an encrypted document (permissions, revision), else null.

public PdfSecurityHandler? Security { get; }

Property Value

PdfSecurityHandler

WasRepaired

True when the xref was rebuilt by scanning a damaged file.

public bool WasRepaired { get; }

Property Value

bool

XrefTable

The cross-reference table of the file (low-level access).

public PdfXrefTable XrefTable { get; }

Property Value

PdfXrefTable

Methods

Dispose()

Closes the document, clears its display-list cache and releases its byte source.

public void Dispose()

DisposeAsync()

Closes the document; the same as Dispose().

public ValueTask DisposeAsync()

Returns

ValueTask

GetBookmarksAsync(CancellationToken)

The outline as bookmarks: destinations resolved through named destinations (the /Dests name tree and the catalog's /Dests) and go-to actions, as PDFium resolves them.

public ValueTask<IReadOnlyList<BookmarkItem>> GetBookmarksAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<IReadOnlyList<BookmarkItem>>

GetPageAsync(int, CancellationToken)

Gets a page object.

public ValueTask<IPdfPage> GetPageAsync(int pageNumber, CancellationToken cancellationToken = default)

Parameters

pageNumber int

The page number, starting at 1.

cancellationToken CancellationToken

Cancels the operation.

Returns

ValueTask<IPdfPage>

Exceptions

ArgumentOutOfRangeException

pageNumber is less than 1 or greater than PageCount.

GetPageDisplayListAsync(int, CancellationToken)

Interprets the page's content stream, annotations and form fields into an immutable display list, on a worker thread. Recent lists are cached (see MaxCachedDisplayListCommands), so a second call for the same page is cheap.

public ValueTask<IPdfDisplayList> GetPageDisplayListAsync(int pageNumber, CancellationToken cancellationToken = default)

Parameters

pageNumber int

The page number, starting at 1.

cancellationToken CancellationToken

Cancels the interpretation.

Returns

ValueTask<IPdfDisplayList>

The display list, ready for a renderer such as SkiaVectorRenderer. Content that is damaged or exceeds a per-page budget of PdfSecurityLimits does not throw: the list keeps what was drawn before it and has Recovered in its features.

Exceptions

ArgumentOutOfRangeException

pageNumber is less than 1 or greater than PageCount.

GetPageInfoAsync(int, CancellationToken)

Gets the size and rotation of a page.

public ValueTask<PageInfo> GetPageInfoAsync(int pageNumber, CancellationToken cancellationToken = default)

Parameters

pageNumber int

The page number, starting at 1.

cancellationToken CancellationToken

Cancels the operation.

Returns

ValueTask<PageInfo>

Exceptions

ArgumentOutOfRangeException

pageNumber is less than 1 or greater than PageCount.

GetPagePrintDisplayListAsync(int, CancellationToken)

The page as a printer gets it: annotations with the Print flag only, NoView ones included (ISO 32000-2 12.5.3). The screen display list is returned when no annotation on the page prints differently from how it shows; otherwise a list is built for the job (not cached).

public ValueTask<IPdfDisplayList> GetPagePrintDisplayListAsync(int pageNumber, CancellationToken cancellationToken = default)

Parameters

pageNumber int
cancellationToken CancellationToken

Returns

ValueTask<IPdfDisplayList>

GetPlateDisplayListAsync(int, PdfPlateRequest, CancellationToken)

The page as it prints (see GetPagePrintDisplayListAsync(int, CancellationToken)), with its colours replaced by the values of the plates request asks for (print production: separations). Not cached.

public ValueTask<IPdfDisplayList> GetPlateDisplayListAsync(int pageNumber, PdfPlateRequest request, CancellationToken cancellationToken = default)

Parameters

pageNumber int
request PdfPlateRequest
cancellationToken CancellationToken

Returns

ValueTask<IPdfDisplayList>

Open(IPdfByteSource, string, PdfSecurityLimits?, string?, IEnumerable<X509Certificate2>?)

Opens a PDF from a byte source, synchronously. The document owns source and disposes it.

public static PdfVectorDocument Open(IPdfByteSource source, string filePath = "Source.pdf", PdfSecurityLimits? limits = null, string? password = null, IEnumerable<X509Certificate2>? certificates = null)

Parameters

source IPdfByteSource

The PDF data, for example a PdfMemoryByteSource or a PdfFileByteSource.

filePath string

A name for the document, reported by FilePath.

limits PdfSecurityLimits

Ceilings for hostile input; null uses Default.

password string

The user or owner password of an encrypted document, or null.

certificates IEnumerable<X509Certificate2>

For public-key encryption: certificates with private keys to try; null uses CertificateSource (the personal certificate stores).

Returns

PdfVectorDocument

The open document. Dispose it when you no longer need it.

Exceptions

PdfSyntaxException

The data is not a PDF, or it is damaged beyond repair.

PdfEncryptedDocumentException

The password or certificate is missing or wrong, or the security handler is not supported.

PdfResourceLimitException

The file exceeds a limit of limits.

OpenAsync(byte[], string, PdfSecurityLimits?, CancellationToken, string?, IEnumerable<X509Certificate2>?)

Opens a PDF from bytes in memory. The document keeps a reference to pdfBytes; do not change the array.

public static ValueTask<PdfVectorDocument> OpenAsync(byte[] pdfBytes, string filePath = "Memory.pdf", PdfSecurityLimits? limits = null, CancellationToken cancellationToken = default, string? password = null, IEnumerable<X509Certificate2>? certificates = null)

Parameters

pdfBytes byte[]

The complete PDF file.

filePath string

A name for the document, reported by FilePath.

limits PdfSecurityLimits

Ceilings for hostile input; null uses Default.

cancellationToken CancellationToken

Cancels the operation before parsing starts.

password string

The user or owner password of an encrypted document, or null.

certificates IEnumerable<X509Certificate2>

For public-key encryption: certificates with private keys to try; null uses CertificateSource (the personal certificate stores).

Returns

ValueTask<PdfVectorDocument>

The open document. Dispose it when you no longer need it.

Exceptions

PdfSyntaxException

The data is not a PDF, or it is damaged beyond repair.

PdfEncryptedDocumentException

The password or certificate is missing or wrong, or the security handler is not supported.

PdfResourceLimitException

The file exceeds a limit of limits.

OpenAsync(string, PdfSecurityLimits?, CancellationToken, string?, IEnumerable<X509Certificate2>?)

Reads a PDF file into memory and opens it.

public static ValueTask<PdfVectorDocument> OpenAsync(string filePath, PdfSecurityLimits? limits = null, CancellationToken cancellationToken = default, string? password = null, IEnumerable<X509Certificate2>? certificates = null)

Parameters

filePath string

The path of the PDF file.

limits PdfSecurityLimits

Ceilings for hostile input; null uses Default.

cancellationToken CancellationToken

Cancels the file read.

password string

The user or owner password of an encrypted document, or null.

certificates IEnumerable<X509Certificate2>

For public-key encryption: certificates with private keys to try; null uses CertificateSource (the personal certificate stores).

Returns

ValueTask<PdfVectorDocument>

The open document. Dispose it when you no longer need it.

Exceptions

PdfSyntaxException

The file is not a PDF, or it is damaged beyond repair.

PdfEncryptedDocumentException

The password or certificate is missing or wrong, or the security handler is not supported.

PdfResourceLimitException

The file exceeds a limit of limits.

SetHiddenAnnotations(IEnumerable<int>)

Leaves these annotations (by object number) out of the screen display lists, for a viewer that draws them itself while they are being changed; printing still draws them. Returns the pages whose display lists were dropped because of the change.

public IReadOnlyList<int> SetHiddenAnnotations(IEnumerable<int> objectNumbers)

Parameters

objectNumbers IEnumerable<int>

Returns

IReadOnlyList<int>