PeachDrawing.PDF
PdfComposer Class
Writes a PDF file: add pages, draw on each one through a PdfCanvas, then Save(Stream).
public sealed class PdfComposer : System.IDisposable
Inheritance System.Object → PdfComposer
Implements System.IDisposable
Remarks
Everything is drawn through the PeachDrawing.Core drawing surface, so code written against
Canvas draws a PDF page the same way it draws a bitmap with PeachDrawing’s raster canvas.
Fonts are embedded and subset; only the glyphs a document draws end up in the file.
A canvas is in layout units, which are points unless the PdfRenderContext was told otherwise (PixelsPerPoint): its origin is the top-left corner of the page and y grows downward. A page is finished when the composer is saved, so a canvas can be kept and drawn on until then. A composer writes one file; make another for the next. It is not thread safe, and neither are its canvases.
| Constructors | |
|---|---|
| PdfComposer(PdfRenderContext, PdfComposerOptions) | Starts a document. |
| Properties | |
|---|---|
| EmbeddedFileNames | The file names of the files the document embeds (EmbeddedFiles), which a FileAttachment annotation (EmbeddedFileName) may point at. Empty until the document is configured, and when it embeds nothing. |
| PageCount | The number of pages added so far. |
| Pages | The pages added so far, in order. |
| Methods | |
|---|---|
| AddBookmarks(IEnumerable<PdfBookmark>) | Adds entries to the document outline (the bookmarks sidebar of a reader). Each entry nests under the nearest preceding entry of the same batch with a shallower level, or sits at the top if there is none - the conventional heading-outline shape. |
| AddNamedDestination(string, int, double) | Names a place in the document, so links (AddDestinationLink(Rect, string, IReadOnlyList<PaintPoint>)) and readers can jump to it. The reader scrolls to put the place at the top of the window, at the width of the page. |
| AddPage(double, double) | Adds a page at the end of the document. |
| Configure(PdfComposerOptions) | Applies options to the document: fixes its format (version, conformance, color management, encryption, embedded files, compression), writes the document information, and writes whatever the claimed conformance level requires (the output intent, the XMP packet). |
| ConsolidateImages() | Merges embedded raster images that encode to byte-identical PDF image objects, keeping one copy and pointing every other reference at it. Call it after all pages are drawn and before Save(Stream): the saved file then drops the duplicates. |
| CreateAnnotationBuilder(PdfRenderContext) | Starts adding annotations that are neither links nor form fields (highlights, notes, stamps, drawings) to the document’s pages. |
| CreateFormBuilder(PdfRenderContext, string) | Starts adding interactive form fields to the document’s pages. |
| CreateTagRecorder(bool) | Starts recording the document’s logical structure, which makes the file a tagged PDF. A recorder replaces the structure tree any earlier one wrote. |
| Dispose() | Releases the document. Canvases returned by AddPage(double, double) are not usable afterwards. |
| Save(Stream) | Finishes the pages and writes the file. Pages can be added and the document saved again: each save writes everything so far. |