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
Objects
Gets the low-level PDF object collection for advanced scenarios.
public IPdfObjectCollection Objects { get; }
Property Value
Methods
AddWatermarkAsync(string)
Adds a simple text watermark to each page.
public Task AddWatermarkAsync(string text)
Parameters
textstring
Returns
AppendPageAsync(Action<PageCreationOptions>?)
Appends a new page to the end of the document.
public Task<Page> AppendPageAsync(Action<PageDictionary.PageCreationOptions>? configureOptions = null)
Parameters
configureOptionsAction<PageDictionary.PageCreationOptions>
Returns
AppendPdfAsync(Stream)
Appends the pages from another PDF stream to the current document.
public Task AppendPdfAsync(Stream stream)
Parameters
streamStream
Returns
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
passwordstring
Returns
Compress(int, int)
Compresses eligible streams in the document.
public void Compress(int dpi, int quality)
Parameters
dpiintReserved for future image downsampling behavior. Must be greater than zero.
qualityintJPEG 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
configureOptionsAction<PageDictionary.PageCreationOptions>
Returns
DecompressAsync()
Removes compression filters from all objects in the PDF.
public Task DecompressAsync()
Returns
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
passwordstring
Returns
DeletePageAsync(int)
Deletes a page by its 1-based page number.
public Task DeletePageAsync(int pageNumber)
Parameters
pageNumberint
Returns
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
disposingbool
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
userPasswordstringownerPasswordstringalgorithmPdfEncryptionAlgorithmpermissionsPdfEncryptionPermissions
Returns
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
pageNumbersIEnumerable<int>
Returns
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
ExtractTextAsync(int)
Extracts text from a single 1-based page number.
public Task<IEnumerable<ExtractedText>> ExtractTextAsync(int pageNumber)
Parameters
pageNumberint
Returns
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
pageNumberintoptionsTextExtractionOptions
Returns
ExtractTextAsync(TextExtractionOptions)
Extracts text from the document using the requested output shape.
public Task<TextExtractionResult> ExtractTextAsync(TextExtractionOptions options)
Parameters
optionsTextExtractionOptions
Returns
GetAllPagesAsync()
Gets every page indirect object in page order.
public Task<IList<IndirectObject>> GetAllPagesAsync()
Returns
GetFormAsync()
Gets the document form wrapper if the PDF contains an AcroForm.
public Task<Form?> GetFormAsync()
Returns
GetMetadataAsync()
Gets the editable document metadata backed by the trailer Info dictionary.
public Task<PdfMetadata> GetMetadataAsync()
Returns
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
GetPageAsync(int)
Gets a page by its 1-based page number.
public Task<Page> GetPageAsync(int pageNumber)
Parameters
pageNumberint
Returns
GetPageCountAsync()
Gets the number of pages in the document.
public Task<int> GetPageCountAsync()
Returns
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
pageNumberintconfigureOptionsAction<PageDictionary.PageCreationOptions>
Returns
Load(Stream)
Loads a PDF from a seekable input stream.
public static Pdf Load(Stream pdfInputStream)
Parameters
pdfInputStreamStream
Returns
New()
Starts a fluent authoring workflow for creating a new PDF with page, text, drawing, image, and watermark operations.
public static PdfAuthoringBuilder New()
Returns
Pages(Action<PdfPagesBuilder>)
Starts a fluent page-editing workflow for an existing or newly created PDF.
public PdfPageEditingBuilder Pages(Action<PdfPagesBuilder> configurePages)
Parameters
configurePagesAction<PdfPagesBuilder>
Returns
RedactionAsync()
Starts a redaction plan for marking text or regions and then applying redaction overlays.
public Task<PdfRedactionPlan> RedactionAsync()
Returns
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
Returns
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
Returns
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
Returns
RemoveHistoryAsync()
Rewrites the document so only the latest live objects are saved.
public Task RemoveHistoryAsync()
Returns
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
outputStreamStream
Returns
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
rotationRotation
Returns
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
certificateX509Certificate2optionsPdfSignatureOptions
Returns
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
pagesPerDocumentint
Returns
Remarks
The returned Pdf instances should be disposed after saving or further editing.