Class PdfPageAssembly
Builds a PDF out of pages taken from one or more existing PDFs, in any order, with any page omitted or repeated — without rasterizing and without re-encoding a single stream.
public sealed class PdfPageAssembly : IDisposable
- Inheritance
-
PdfPageAssembly
- Implements
- Inherited Members
Examples
using var assembly = new PdfPageAssembly();
int cover = assembly.AddSource("cover.pdf");
int body = assembly.AddSource("body.pdf");
assembly.AppendAll(cover).AppendRange(body, PageRange.Parse("2-"));
PdfAssemblyResult result = assembly.Save("combined.pdf");
Remarks
Delete, reorder, merge, extract, split and duplicate are one operation behind six spellings: build a list of (source, page) pairs and write it. Delete is every page except the selected ones; reorder is a permutation of one source; merge is a concatenation across several; extract is a subset; split is several extracts; duplicate is the same pair twice. PdfPages spells all six in terms of this class, and adds no copying of its own.
Pages move whole. Their content streams, fonts, images and resources are copied in the encoded form the source held, so the assembled page renders identically to the page it came from and extracts the same text. What has to be repaired is everything that pointed at a page — links, named destinations, outline entries and page labels — and what cannot be carried is counted on PdfAssemblyResult and reported as a diagnostic rather than dropped in silence.
One instance per thread, like PdfDocument: it holds open documents and the identity map of a copy in progress.
Constructors
- PdfPageAssembly()
Initializes an assembly with the default settings.
- PdfPageAssembly(PdfAssemblyOptions?)
Initializes an assembly.
Properties
- PageCount
Gets the number of pages appended so far.
- SourceCount
Gets the number of documents added as sources.
Methods
- AddSource(byte[], string?)
Adds a document as a source and returns its index.
- AddSource(Stream, string?)
Adds a document as a source and returns its index.
- AddSource(string, string?)
Adds a document as a source and returns its index.
- AppendAll(int)
Appends every page of a source, in the source's own order.
- AppendPage(int, int)
Appends one page of a source, and may be called again for the same page.
- AppendRange(int, PageRange)
Appends the selected pages of a source, in ascending page order.
- Dispose()
Closes every source document.
- GetSourcePageCount(int)
Gets the number of pages a source has.
- Save(string)
Writes the assembled document to a file.
- WriteTo(Stream)
Writes the assembled document.