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
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.
kind:method, kind:property, kind:ctor. Press Esc to clear.FontGets the font set with SetFont(PdfCanvasFont, Double), or null before any (text state, saved and restored with the graphics state).FontSizeGets the font size set with SetFont(PdfCanvasFont, Double), or 0 before any.IsInTextObjectGets a value indicating whether a text object is open (between BeginText() and EndText()).MarkedContentDepthGets the number of marked-content sequences begun and not yet ended.StateDepthGets the number of graphics states saved with SaveState() and not yet restored.BeginArtifact()Begins an artifact without a property list (/Artifact BMC): content that is not part of the document's logical structure.BeginArtifact(PdfArtifactType, String?, PdfArtifactEdges, Nullable<PdfRectangle>)Begins an artifact of type with its subtype, attached edges and bounding box.BeginArtifact(PdfArtifactType)Begins an artifact of type (/Artifact <</Type ...>> BDC).BeginMarkedContent(String, CosDictionary)Begins a marked-content sequence with an inline property list (BDC), such as an artifact's Type and Subtype.BeginMarkedContent(String)Begins a marked-content sequence without a property list (BMC), such as a generic Artifact.BeginOptionalContent(PdfOptionalContentGroup)Begins optional content belonging to group (/OC /name BDC): visible only while the group is ON.BeginOptionalContent(PdfOptionalContentMembership)Begins optional content whose visibility membership decides (/OC /name BDC).BeginTaggedContent(PdfStructureElement, CosDictionary)Begins a tagged marked-content sequence that is a content item of element, with more properties.BeginTaggedContent(PdfStructureElement, PdfPage?, CosDictionary?)Begins a tagged marked-content sequence that is a content item of element, on a page or in a form drawn on page.BeginTaggedContent(PdfStructureElement)Begins a tagged marked-content sequence that is a content item of element: allocates the page's next MCID, links it into the structure tree and writes /S <</MCID n>> BDC, where S is the element's structure type.BeginText()Begins a text object (BT): the text matrix and the text line matrix start as the identity.Clip(FillRule)Marks the path being built as a clip (W or W*); the painting call that ends the path then narrows the clipping path.CloseAndStroke()Closes the last subpath and strokes the path (s), and ends it.CloseFillAndStroke(FillRule)Closes the last subpath, fills, then strokes the path (b or b*), and ends it.ClosePath()Closes the current subpath with a straight line to its start (h).CurveTo(Double, Double, Double, Double, Double, Double)Appends a cubic Bézier curve to (x3, y3) with two control points (c).Dispose()Ends a path still being built, restores every saved state and stores what was drawn; nothing is stored when nothing was drawn.DrawForm(PdfFormXObject)Paints a form XObject of this document (Do), with the form's matrix and bounding box.DrawImage(PdfImage, Double, Double, Double, Double)Paints an image XObject of this document into a rectangle of user space (q w 0 0 h x y cm /Im Do Q).DrawImage(PdfImage)Paints an image XObject of this document into the unit square of user space (Do).EndMarkedContent()Ends the innermost marked-content sequence (EMC).EndPath()Ends the path without painting it (n): with Clip(FillRule), narrows the clipping path only.EndText()Ends the text object (ET); glyphs shown in a clipping rendering mode then narrow the clipping path.Fill(FillRule)Fills the path (f or f*), closing open subpaths, and ends it.FillAndStroke(FillRule)Fills, then strokes the path (B or B*), and ends it.LineTo(Double, Double)Appends a straight line to (x, y) (l).MoveText(Double, Double)Moves to the start of the next line, offset from the start of the current one by (x, y) (Td).MoveTextAndSetLeading(Double, Double)As MoveText(Double, Double), and sets the leading to −y (TD).MoveTo(Double, Double)Begins a new subpath at (x, y) (m), beginning a path when none is being built.MoveToNextLine()Moves to the start of the next line, the leading below the current one (T*).PaintShading(PdfShading)Paints a shading over the current clipping region (sh), in the current user space.Rectangle(Double, Double, Double, Double)Appends a rectangle as a complete closed subpath (re), beginning a path when none is being built.RestoreState()Restores the graphics state saved last (Q).Rotate(Double)Rotates user space counterclockwise by degrees (cos sin −sin cos 0 0 cm).SaveState()Saves the graphics state (q).Scale(Double, Double)Scales user space (sx 0 0 sy 0 0 cm).SetBlendMode(BlendMode)Sets the blend mode (BM through a graphics state parameter dictionary and gs).SetCharacterSpacing(Double)Sets the character spacing (Tc), added to every glyph's displacement.SetDashPattern(ReadOnlySpan<Double>, Double)Sets the line dash pattern (d); an empty dashArray draws solid lines.SetFillAlpha(Double)Sets the constant opacity of fills (ca through a graphics state parameter dictionary and gs).SetFillColor(PdfColor)Sets the colour used for filling (g, rg, k, or cs and sc/scn).SetFillPattern(PdfPattern)Sets a coloured tiling pattern or a shading pattern as the fill colour (/Pattern cs /name scn).SetFillPattern(PdfTilingPattern, PdfColor)Sets an uncoloured tiling pattern, painted in color, as the fill colour (/CSn cs c1 … cn /name scn).SetFlatness(Double)Sets the flatness tolerance (i).SetFont(PdfCanvasFont, Double)Sets the font and the font size (Tf).SetHorizontalScaling(Double)Sets the horizontal scaling (Tz), which stretches glyphs and spacing horizontally.SetLineCap(LineCap)Sets the line cap style (J).SetLineJoin(LineJoin)Sets the line join style (j).SetLineWidth(Double)Sets the line width (w).SetMiterLimit(Double)Sets the miter limit (M).SetRenderingIntent(RenderingIntent)Sets the colour rendering intent (ri, PDF 1.1).SetSoftMask(PdfSoftMask?)Sets the soft mask that later painting is masked by (SMask through a graphics state parameter dictionary and gs), or removes it (/SMask /None).SetStrokeAlpha(Double)Sets the constant opacity of strokes (CA through a graphics state parameter dictionary and gs).SetStrokeColor(PdfColor)Sets the colour used for stroking (G, RG, K, or CS and SC/SCN).SetStrokePattern(PdfPattern)Sets a coloured tiling pattern or a shading pattern as the stroke colour (/Pattern CS /name SCN).SetStrokePattern(PdfTilingPattern, PdfColor)Sets an uncoloured tiling pattern, painted in color, as the stroke colour (/CSn CS c1 … cn /name SCN).SetTextLeading(Double)Sets the text leading (TL), the distance MoveToNextLine() moves down.SetTextMatrix(Matrix)Sets the text matrix and the text line matrix (Tm).SetTextRenderingMode(TextRenderingMode)Sets the text rendering mode (Tr): fill, stroke, invisible, or add the glyphs to the clipping path.SetTextRise(Double)Sets the text rise (Ts), which moves the baseline up (superscript) or down (subscript).SetWordSpacing(Double)Sets the word spacing (Tw), added to the displacement of every single-byte code 32.ShowText(ShapedText, ReadOnlySpan<Double>)Shows shaped text with an extra adjustment after each glyph (TJ): positive moves the next glyph left (closer), negative right.ShowText(ShapedText)Shows shaped text (Tj, or TJ where glyph advances differ from glyph widths) at the current text position.ShowText(ReadOnlySpan<Char>, Boolean)Shows text in the current font at the current text position (Tj, or TJ when it is kerned).ShowText(ReadOnlySpan<Char>, ReadOnlySpan<Double>)Shows text with an explicit adjustment after each character (TJ): positive moves the next glyph left (closer), negative right.ShowText(ReadOnlySpan<Char>)Shows text in the current font at the current text position, without kerning (Tj).ShowTextOnNextLine(ReadOnlySpan<Char>, Double, Double)Sets the word and character spacing, moves to the next line and shows text there (").ShowTextOnNextLine(ReadOnlySpan<Char>)Moves to the next line and shows text there (', the same as MoveToNextLine() then ShowText(ReadOnlySpan<Char>, Boolean)).Stroke()Strokes the path (S) and ends it.Transform(Matrix)Concatenates matrix to the current transformation matrix (cm).Translate(Double, Double)Moves the origin of user space by (x, y) (1 0 0 1 x y cm).