Table of Contents

Class Pdf

Namespace
ZingPDF
Assembly
ZingPDF.dll

Default implementation of IPdf.

public class Pdf : IPdf, IDisposable
Inheritance
Pdf
Implements
Inherited Members

Properties

Data

Gets the underlying source stream for the PDF.

public Stream Data { get; }

Property Value

Stream

Objects

Gets the low-level PDF object collection for advanced scenarios.

public IPdfObjectCollection Objects { get; }

Property Value

IPdfObjectCollection

Methods

AddWatermarkAsync(string)

Adds a simple text watermark to each page.

public Task AddWatermarkAsync(string text)

Parameters

text string

Returns

Task

AppendPageAsync(Action<PageCreationOptions>?)

Appends a new page to the end of the document.

public Task<Page> AppendPageAsync(Action<PageDictionary.PageCreationOptions>? configureOptions = null)

Parameters

configureOptions Action<PageDictionary.PageCreationOptions>

Returns

Task<Page>

AppendPdfAsync(Stream)

Appends the pages from another PDF stream to the current document.

public Task AppendPdfAsync(Stream stream)

Parameters

stream Stream

Returns

Task

AuthenticateAsync(string)

Unlocks the PDF for reading and/or writing. The password can be a user password or an owner password.

public Task AuthenticateAsync(string password)

Parameters

password string

Returns

Task

Compress(int, int)

Compresses eligible streams in the document.

public void Compress(int dpi, int quality)

Parameters

dpi int

Reserved for future image downsampling behavior. Must be greater than zero.

quality int

JPEG recompression quality from 1 to 100.

Create(Action<PageCreationOptions>?)

Creates a new blank PDF containing a single page.

public static Pdf Create(Action<PageDictionary.PageCreationOptions>? configureOptions = null)

Parameters

configureOptions Action<PageDictionary.PageCreationOptions>

Returns

Pdf

DecompressAsync()

Removes compression filters from all objects in the PDF.

public Task DecompressAsync()

Returns

Task

Remarks

This applies an incremental update to the PDF with all objects decompressed. This can add significant size to the PDF. Typically, this is used to make the source code of a PDF more readable.

DecryptAsync(string)

Authenticates with the supplied password and saves the PDF without encryption.

public Task DecryptAsync(string password)

Parameters

password string

Returns

Task

DeletePageAsync(int)

Deletes a page by its 1-based page number.

public Task DeletePageAsync(int pageNumber)

Parameters

pageNumber int

Returns

Task

Dispose()

Disposes the document stream and scoped services used by this PDF instance.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

EncryptAsync(string, string?, PdfEncryptionAlgorithm, PdfEncryptionPermissions)

Saves the PDF using standard password protection.

public Task EncryptAsync(string userPassword, string? ownerPassword = null, PdfEncryptionAlgorithm algorithm = PdfEncryptionAlgorithm.Rc4_128, PdfEncryptionPermissions permissions = PdfEncryptionPermissions.All)

Parameters

userPassword string
ownerPassword string
algorithm PdfEncryptionAlgorithm
permissions PdfEncryptionPermissions

Returns

Task

Remarks

If the source PDF is already encrypted, authenticate it first so the document can be rewritten. By default this preserves the legacy RC4 writer behaviour for compatibility. Pass Aes128 or Aes256 to write AES-encrypted documents.

ExportPagesAsync(IEnumerable<int>)

Exports a new PDF containing the selected 1-based page numbers in the requested order.

public Task<Pdf> ExportPagesAsync(IEnumerable<int> pageNumbers)

Parameters

pageNumbers IEnumerable<int>

Returns

Task<Pdf>

Remarks

The returned Pdf should be disposed after saving or further editing. Page numbers must be unique.

ExtractTextAsync()

Extracts text from the document.

public Task<IEnumerable<ExtractedText>> ExtractTextAsync()

Returns

Task<IEnumerable<ExtractedText>>

ExtractTextAsync(int)

Extracts text from a single 1-based page number.

public Task<IEnumerable<ExtractedText>> ExtractTextAsync(int pageNumber)

Parameters

pageNumber int

Returns

Task<IEnumerable<ExtractedText>>

ExtractTextAsync(int, TextExtractionOptions)

Extracts text from a single 1-based page number using the requested output shape.

public Task<TextExtractionResult> ExtractTextAsync(int pageNumber, TextExtractionOptions options)

Parameters

pageNumber int
options TextExtractionOptions

Returns

Task<TextExtractionResult>

ExtractTextAsync(TextExtractionOptions)

Extracts text from the document using the requested output shape.

public Task<TextExtractionResult> ExtractTextAsync(TextExtractionOptions options)

Parameters

options TextExtractionOptions

Returns

Task<TextExtractionResult>

GetAllPagesAsync()

Gets every page indirect object in page order.

public Task<IList<IndirectObject>> GetAllPagesAsync()

Returns

Task<IList<IndirectObject>>

GetFormAsync()

Gets the document form wrapper if the PDF contains an AcroForm.

public Task<Form?> GetFormAsync()

Returns

Task<Form>

GetMetadataAsync()

Gets the editable document metadata backed by the trailer Info dictionary.

public Task<PdfMetadata> GetMetadataAsync()

Returns

Task<PdfMetadata>

Remarks

Changes are persisted when SaveAsync(Stream) is called. Saving also stamps the metadata producer as ZingPDF and refreshes the modification date.

GetOrCreateFormAsync()

Gets the document form wrapper, creating an empty AcroForm when the document does not already have one.

public Task<Form> GetOrCreateFormAsync()

Returns

Task<Form>

GetPageAsync(int)

Gets a page by its 1-based page number.

public Task<Page> GetPageAsync(int pageNumber)

Parameters

pageNumber int

Returns

Task<Page>

GetPageCountAsync()

Gets the number of pages in the document.

public Task<int> GetPageCountAsync()

Returns

Task<int>

InsertPageAsync(int, Action<PageCreationOptions>?)

Inserts a new page before the specified 1-based page number.

public Task<Page> InsertPageAsync(int pageNumber, Action<PageDictionary.PageCreationOptions>? configureOptions = null)

Parameters

pageNumber int
configureOptions Action<PageDictionary.PageCreationOptions>

Returns

Task<Page>

Load(Stream)

Loads a PDF from a seekable input stream.

public static Pdf Load(Stream pdfInputStream)

Parameters

pdfInputStream Stream

Returns

Pdf

New()

Starts a fluent authoring workflow for creating a new PDF with page, text, drawing, image, and watermark operations.

public static PdfAuthoringBuilder New()

Returns

PdfAuthoringBuilder

Pages(Action<PdfPagesBuilder>)

Starts a fluent page-editing workflow for an existing or newly created PDF.

public PdfPageEditingBuilder Pages(Action<PdfPagesBuilder> configurePages)

Parameters

configurePages Action<PdfPagesBuilder>

Returns

PdfPageEditingBuilder

RedactionAsync()

Starts a redaction plan for marking text or regions and then applying redaction overlays.

public Task<PdfRedactionPlan> RedactionAsync()

Returns

Task<PdfRedactionPlan>

RegisterStandardFontAsync(string, string?)

Registers one of the standard PDF fonts for use with page text APIs.

public Task<PdfFont> RegisterStandardFontAsync(string fontName, string? resourceName = null)

Parameters

fontName string
resourceName string

Returns

Task<PdfFont>

RegisterTrueTypeFontAsync(Stream, string?, string?)

Registers an embedded TrueType font from a stream.

public Task<PdfFont> RegisterTrueTypeFontAsync(Stream fontData, string? resourceName = null, string? fontName = null)

Parameters

fontData Stream
resourceName string
fontName string

Returns

Task<PdfFont>

RegisterTrueTypeFontAsync(string, string?, string?)

Registers an embedded TrueType font from a file path.

public Task<PdfFont> RegisterTrueTypeFontAsync(string fontPath, string? resourceName = null, string? fontName = null)

Parameters

fontPath string
resourceName string
fontName string

Returns

Task<PdfFont>

RemoveHistoryAsync()

Rewrites the document so only the latest live objects are saved.

public Task RemoveHistoryAsync()

Returns

Task

Remarks

Unlike the default save path, this removes prior incremental-update history instead of preserving it.

SaveAsync(Stream)

Saves the document.

public Task SaveAsync(Stream outputStream)

Parameters

outputStream Stream

Returns

Task

Remarks

By default this writes an incremental update. If RemoveHistoryAsync() has been called, the document is rewritten with only the latest live objects. The current save pipeline requires a writable, seekable output stream because it inspects stream length and, in some save paths, resets and truncates the stream before writing. When saving to a different stream, that output stream must also be empty.

SetRotationAsync(Rotation)

Sets the rotation for every page in the document.

public Task SetRotationAsync(Rotation rotation)

Parameters

rotation Rotation

Returns

Task

SignInvisibleAsync(X509Certificate2, PdfSignatureOptions?)

Signs the document by creating a hidden signature field and writing a detached CMS signature.

public Task SignInvisibleAsync(X509Certificate2 certificate, PdfSignatureOptions? options = null)

Parameters

certificate X509Certificate2
options PdfSignatureOptions

Returns

Task

SplitAsync(int)

Splits the document into multiple PDFs with up to the requested number of pages each.

public Task<IReadOnlyList<Pdf>> SplitAsync(int pagesPerDocument)

Parameters

pagesPerDocument int

Returns

Task<IReadOnlyList<Pdf>>

Remarks

The returned Pdf instances should be disposed after saving or further editing.