PdfCanvas Class

Definition

Draws on a page or a form XObject: paths, fills, strokes, clips, transforms, line attributes, dash patterns, colours and transparency, written as content stream operators. Dispose it to store what was drawn.

public sealed class PdfCanvas : IDisposable

Remarks

ISO 32000-2 §8.2 (graphics objects), §8.4 (graphics state), §8.5 (path construction and painting), §8.6 (colour spaces) and §9.2–9.4 (text objects, text state, text positioning and showing). Get a canvas with CreateCanvas() or CreateCanvas(). Each call writes the operator it names; the canvas keeps the order Figure 9 of §8.2 requires: a path object is begun with MoveTo(Double, Double) or Rectangle(Double, Double, Double, Double), continued with path construction, optionally marked as a clip with Clip(FillRule), and ended by exactly one painting call; any other call while a path is being built throws InvalidOperationException. A text object is begun with BeginText() and ended with EndText(); inside it only general graphics state, colour, text state, text positioning and text showing calls are allowed (no paths, q/Q, transforms or XObjects).

Resources are added to the page's or form's resource dictionary as they are used, each under a name the dictionary does not have yet; using the same colour space, graphics state parameters or form again reuses its name (§7.8.3). Graphics state parameter dictionaries are written once per document for the same values. Using a feature records the PDF version it needs: a save raises the document's version to it, or refuses in strict mode.

Dispose() ends a path still being built (n) and a text object still open (ET), restores every state still saved (Q), and stores the content: on a page, as a new content stream after the page's existing content, which is wrapped in q and Q so the state it leaves does not reach the new content; on a form, appended to the form's own stream the same way. The stream is written unfiltered; a save compresses it (StreamCompression). A canvas is a mutation of its document: no read may run concurrently with it, and it is not thread-safe.

Tip: use kind:method, kind:property, kind:ctor. Press Esc to clear.

Properties (5)

Methods (71)