Class PdfVectorDocument
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
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
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
HiddenAnnotations
The annotations (by object number) the screen display lists leave out.
public IReadOnlySet<int> HiddenAnnotations { get; }
Property Value
IsEncrypted
True when the file is encrypted (and was opened with a valid password).
public bool IsEncrypted { get; }
Property Value
IsOpen
False after the document is disposed.
public bool IsOpen { get; }
Property Value
Metadata
The document information and permissions read at open time.
public DocumentMetadata Metadata { get; }
Property Value
PageCount
The number of pages.
public int PageCount { get; }
Property Value
PageTree
The flattened page tree (low-level access).
public PdfPageTree PageTree { get; }
Property Value
Resolver
Resolves indirect objects of the file (low-level access).
public PdfObjectResolver Resolver { get; }
Property Value
Security
The Standard security handler of an encrypted document (permissions, revision), else null.
public PdfSecurityHandler? Security { get; }
Property Value
WasRepaired
True when the xref was rebuilt by scanning a damaged file.
public bool WasRepaired { get; }
Property Value
XrefTable
The cross-reference table of the file (low-level access).
public PdfXrefTable XrefTable { get; }
Property Value
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
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
cancellationTokenCancellationToken
Returns
GetPageAsync(int, CancellationToken)
Gets a page object.
public ValueTask<IPdfPage> GetPageAsync(int pageNumber, CancellationToken cancellationToken = default)
Parameters
pageNumberintThe page number, starting at 1.
cancellationTokenCancellationTokenCancels the operation.
Returns
Exceptions
- ArgumentOutOfRangeException
pageNumberis 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
pageNumberintThe page number, starting at 1.
cancellationTokenCancellationTokenCancels 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
pageNumberis 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
pageNumberintThe page number, starting at 1.
cancellationTokenCancellationTokenCancels the operation.
Returns
Exceptions
- ArgumentOutOfRangeException
pageNumberis 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
pageNumberintcancellationTokenCancellationToken
Returns
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
pageNumberintrequestPdfPlateRequestcancellationTokenCancellationToken
Returns
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
sourceIPdfByteSourceThe PDF data, for example a PdfMemoryByteSource or a PdfFileByteSource.
filePathstringA name for the document, reported by FilePath.
limitsPdfSecurityLimitsCeilings for hostile input; null uses Default.
passwordstringThe user or owner password of an encrypted document, or null.
certificatesIEnumerable<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
pdfBytesbyte[]The complete PDF file.
filePathstringA name for the document, reported by FilePath.
limitsPdfSecurityLimitsCeilings for hostile input; null uses Default.
cancellationTokenCancellationTokenCancels the operation before parsing starts.
passwordstringThe user or owner password of an encrypted document, or null.
certificatesIEnumerable<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
filePathstringThe path of the PDF file.
limitsPdfSecurityLimitsCeilings for hostile input; null uses Default.
cancellationTokenCancellationTokenCancels the file read.
passwordstringThe user or owner password of an encrypted document, or null.
certificatesIEnumerable<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
objectNumbersIEnumerable<int>