PeachDrawing.PDF

PdfOperation Class

Works on PDF files that already exist: take some of their pages, merge several into one, lay one over another, attach files, extend the metadata and protect or unprotect the result. Steps are chained and nothing is written until Save(string).

public sealed class PdfOperation

Inheritance System.Object → PdfOperation

Example

PdfOperation.LoadFile("a.pdf").TakePages("1-5").MergeFile("b.pdf", "1,3,5").Save("merged.pdf");

Remarks

Pages are carried across by drawing them again into the new file (see PdfPageSource), together with their links, form fields, annotations, named destinations and outline. Whatever the importer cannot draw is left out of the page and reported by Warnings after saving.

Steps run in the order they are chained: a layer lands on the pages the output has when it is added, and a later TakePages(string) carries those pages’ layers with them. A mistake in a step (a wrong password, a selector that names a page the file lacks) is reported by the call that made it.

Properties  
PageCount The number of pages the output has so far.
Warnings The features the importer could not draw, named once each, found by the last save.
Methods  
AddAttachment(PdfFileAttachment) Attaches a file to the output.
AppendTo(PdfComposer, PdfRenderContext, Nullable<PdfCopyMode>) Adds the pages of this operation after the pages composer already has, instead of writing a file of their own: the document being composed keeps its own conformance, encryption and metadata, and these pages become part of it.
Decrypt() Writes the output with no protection, even when the pages came from an encrypted file or an earlier Encrypt(PdfEncryptionOptions) step asked for some. A file opened here is already read with its password, so this only has to stop it being protected again.
Encrypt(PdfEncryptionOptions) Protects the output with a password and permissions.
ExtendMetadata(string) Adds elements to the XMP metadata of the output, inside its rdf:Description.
Linearize() Writes the output in the linearized layout (“fast web view”), so a viewer fetching it over a network can show the first page before the rest has arrived. See Linearize.
LoadBytes(byte[], string) Opens a PDF held in memory.
LoadFile(string) Opens a PDF that needs no password.
LoadFile(string, string) Opens a PDF protected with a password.
LoadStream(Stream, string) Opens a PDF read from a stream, which is read to the end and left open.
MergeBytes(byte[], string, string) Adds the pages of a PDF held in memory to the end.
MergeFile(string, string, string) Adds the pages of another PDF to the end.
MergeStream(Stream, string, string) Adds the pages of a PDF read from a stream to the end.
OverlayFile(PdfLayerConfiguration) Draws pages of another PDF over pages of the output.
RemoveRestrictions() Writes the output with no permission restrictions. Pages are drawn again rather than copied, so a restriction or a signature of the original is never carried across; this is the same as Decrypt() and exists for symmetry with that step.
Save(string) Writes the output to a file, replacing it.
Save(Stream) Writes the output to a stream, which is left open.
TakePages(string) Keeps only the pages a selector names, in the order it names them.
ToArray() Writes the output to memory.
UnderlayFile(PdfLayerConfiguration) Draws pages of another PDF under pages of the output, so the output’s own content hides them where it is opaque.
WithCopyMode(PdfCopyMode) Chooses how the pages of the loaded files are carried into the output.