PdfContentBuilder Class

Writes the operators of a content stream (ISO 32000-2, 8 and 9): graphics state, paths, colors, text, images and marked content. The resources the content uses (fonts, images) are added to the resource dictionary of the page.

public sealed class PdfContentBuilder

Remarks

Coordinates are in user space: by default the origin is the lower-left corner of the page, x increases to the right and y upward, in 1/72 inch. The methods return the builder, so that calls can be chained.

The builder checks the structure of the content: text operators are only allowed between PdfContentBuilder.BeginText and PdfContentBuilder.EndText, PdfContentBuilder.RestoreGraphicsState and PdfContentBuilder.EndMarkedContent need a matching call before them, and a text is only shown once a font is set. An operator whose arguments are not valid throws before it writes anything, so the content stays valid. PdfContentBuilder.Complete checks that the content is balanced: every PdfContentBuilder.SaveGraphicsState, PdfContentBuilder.BeginText and BeginMarkedContent call matched.

Properties

NameDescription
GraphicsStateDepthGets the number of PdfContentBuilder.SaveGraphicsState calls that are not matched by a PdfContentBuilder.RestoreGraphicsState call.
IsInTextObjectGets a value indicating whether a text object is open: PdfContentBuilder.BeginText was called, and PdfContentBuilder.EndText was not.
MarkedContentDepthGets the number of BeginMarkedContent, PdfContentBuilder.BeginStructureElement and PdfContentBuilder.BeginArtifact calls that are not matched by an PdfContentBuilder.EndMarkedContent call.

GraphicsStateDepth

PdfContentBuilder.cs

Gets the number of PdfContentBuilder.SaveGraphicsState calls that are not matched by a PdfContentBuilder.RestoreGraphicsState call.

public int GraphicsStateDepth { get; }

Property value

int

IsInTextObject

PdfContentBuilder.cs

Gets a value indicating whether a text object is open: PdfContentBuilder.BeginText was called, and PdfContentBuilder.EndText was not.

public bool IsInTextObject { get; }

Property value

bool

MarkedContentDepth

PdfContentBuilder.cs

Gets the number of BeginMarkedContent, PdfContentBuilder.BeginStructureElement and PdfContentBuilder.BeginArtifact calls that are not matched by an PdfContentBuilder.EndMarkedContent call.

public int MarkedContentDepth { get; }

Property value

int

Methods

NameDescription
AppendRawContent(ReadOnlySpan<byte>)Appends content as it is, for operators the builder has no method for. The builder does not check it.
BeginArtifact(PdfArtifactType)Begins an artifact (/Artifact BDC, 14.8.2.2): content that is not part of the logical structure, such as a page number or a decoration, until the matching PdfContentBuilder.EndMarkedContent.
BeginMarkedContent(string)Begins a marked-content sequence (BMC).
BeginMarkedContent(string, PdfDictionary)Begins a marked-content sequence with a property list (BDC), such as <</MCID 0>>.
BeginStructureElement(PdfStructureElement)Begins the marked content of an element of the structure tree (BDC with a marked-content identifier, ISO 32000-2, 14.7.5.2): the content until the matching PdfContentBuilder.EndMarkedContent belongs to the element.
BeginText()Begins a text object (BT): the text matrix is reset to the identity.
Circle(double, double, double)Appends a circle as a closed subpath of four Bezier curves.
Clip(PdfFillRule)Intersects the clipping path with the current path (W or W*); the path must then be painted or ended with PdfContentBuilder.EndPath.
CloseAndStroke()Closes and strokes the path (s).
CloseFillAndStroke(PdfFillRule)Closes, fills, then strokes the path (b or b*).
ClosePath()Closes the current subpath with a straight line to its start (h).
Complete()Checks that the content is balanced, and ends it: every PdfContentBuilder.SaveGraphicsState, PdfContentBuilder.BeginText and BeginMarkedContent call is matched. The builder cannot write anymore.
CurveTo(double, double, double, double, double, double)Appends a cubic Bezier curve (c).
CurveToEndPoint(double, double, double, double)Appends a cubic Bezier curve whose second control point is the end point (y).
CurveToFromCurrentPoint(double, double, double, double)Appends a cubic Bezier curve whose first control point is the current point (v).
DrawForm(PdfForm)Paints a form XObject (Do). The form is added to the resources.
DrawImage(PdfImage, double, double, double, double)Draws an image in a rectangle of the user space: q, cm, Do, Q. The image is added to the resources.
DrawTable(PdfTable, PdfRectangle, PdfTableDrawResult?)Draws a table in a rectangle: the rows from the top of the rectangle, as many as fit in its height, with the borders, the backgrounds and the texts of the cells broken into lines. Call it again with the result to continue the table in another rectangle (on the next page): the header rows are drawn again at its top.
DrawText(string, PdfFont, double, double, double)Shows a line of text at a position, in its own text object: BT, Tf, Td, Tj, ET.
DrawTextBox(string, PdfFont, double, PdfRectangle, PdfTextBoxOptions?)Draws a text in a rectangle, broken into lines that fit its width at the break opportunities of the Unicode line breaking algorithm (UAX #14): after the spaces and the hyphens, between ideographs. A word wider than the rectangle is broken between its characters. The line feeds of the text start new paragraphs. The lines that do not fit in the height of the rectangle are not drawn.
DrawTextBox(string, PdfFont, double, PdfRectangle, PdfTextBoxOptions?, string)Draws a text in a rectangle, broken into lines, and returns the text that does not fit, to draw it in another rectangle (the next column or page).
Ellipse(double, double, double, double)Appends an ellipse as a closed subpath of four Bezier curves.
EndMarkedContent()Ends the marked-content sequence of the matching BeginMarkedContent call (EMC).
EndPath()Ends the path without painting it (n), after PdfContentBuilder.Clip.
EndText()Ends the text object (ET).
Fill(PdfFillRule)Fills the path (f or f*).
FillAndStroke(PdfFillRule)Fills, then strokes the path (B or B*).
LineTo(double, double)Appends a straight line to a point (l).
MarkPoint(string)Marks a point of the content (MP).
MarkPoint(string, PdfDictionary)Marks a point of the content with a property list (DP).
MoveTextPosition(double, double)Moves to the start of the next line, offset from the start of the current line (Td).
MoveTextPositionAndSetLeading(double, double)Moves to the start of the next line, offset from the start of the current line, and sets the leading to -y (TD).
MoveTo(double, double)Begins a new subpath at a point (m).
MoveToNextLine()Moves to the start of the next line, using the leading (T*).
PaintShading(PdfShading)Paints a shading over the clipping region (sh). The shading is added to the resources.
PaintXObject(string)Paints an external object of the resources by its name (Do).
Rectangle(PdfRectangle)Appends a rectangle as a closed subpath (re).
Rectangle(double, double, double, double)Appends a rectangle as a closed subpath (re).
RestoreGraphicsState()Restores the graphics state saved by the matching PdfContentBuilder.SaveGraphicsState call (Q).
Rotate(double)Rotates the user space counterclockwise.
SaveGraphicsState()Saves the graphics state (q).
Scale(double, double)Scales the user space.
SetCharacterSpacing(double)Sets the character spacing (Tc), added after each glyph, in unscaled text space units.
SetDashPattern(ReadOnlySpan<double>, double)Sets the dash pattern (d). An empty array draws solid lines.
SetFillCmyk(double, double, double, double)Sets the nonstroking color in DeviceCMYK (k).
SetFillColor(PdfColor)Sets the nonstroking color, used to fill paths and text (g, rg or k).
SetFillColorComponents(ReadOnlySpan<double>)Sets the components of the nonstroking color in the current nonstroking color space (scn).
SetFillColorSpace(string)Sets the nonstroking color space (cs): a device color space name, or the name of a color space of the resources.
SetFillGray(double)Sets the nonstroking color in DeviceGray (g).
SetFillPattern(PdfPattern)Sets a colored pattern as the nonstroking color (/Pattern cs, scn). The pattern is added to the resources.
SetFillPattern(PdfTilingPattern, PdfColor)Sets an uncolored tiling pattern, painted with a color, as the nonstroking color. The pattern is added to the resources.
SetFillRgb(double, double, double)Sets the nonstroking color in DeviceRGB (rg).
SetFlatness(double)Sets the flatness tolerance (i).
SetFont(PdfFont, double)Sets the font and the font size (Tf). The font is added to the resources.
SetGraphicsState(PdfExtGState)Sets the parameters of a graphics state parameter dictionary (gs), such as the transparency. The dictionary is added to the resources.
SetHorizontalScaling(double)Sets the horizontal scaling of the glyphs (Tz), in percent.
SetLineCap(PdfLineCap)Sets the line cap style (J).
SetLineJoin(PdfLineJoin)Sets the line join style (j).
SetLineWidth(double)Sets the line width (w).
SetMiterLimit(double)Sets the miter limit (M).
SetRenderingIntent(string)Sets the color rendering intent (ri), such as RelativeColorimetric or Perceptual.
SetStrokeCmyk(double, double, double, double)Sets the stroking color in DeviceCMYK (K).
SetStrokeColor(PdfColor)Sets the stroking color (G, RG or K).
SetStrokeColorComponents(ReadOnlySpan<double>)Sets the components of the stroking color in the current stroking color space (SCN).
SetStrokeColorSpace(string)Sets the stroking color space (CS): a device color space name, or the name of a color space of the resources.
SetStrokeGray(double)Sets the stroking color in DeviceGray (G).
SetStrokePattern(PdfPattern)Sets a colored pattern as the stroking color (/Pattern CS, SCN). The pattern is added to the resources.
SetStrokePattern(PdfTilingPattern, PdfColor)Sets an uncolored tiling pattern, painted with a color, as the stroking color. The pattern is added to the resources.
SetStrokeRgb(double, double, double)Sets the stroking color in DeviceRGB (RG).
SetTextLeading(double)Sets the text leading (TL): the distance between the baselines of consecutive lines.
SetTextMatrix(PdfMatrix)Sets the text matrix and the text line matrix (Tm).
SetTextRenderingMode(PdfTextRenderingMode)Sets the text rendering mode (Tr).
SetTextRise(double)Sets the text rise (Ts): the distance to move the baseline up (superscript) or down (subscript).
SetWordSpacing(double)Sets the word spacing (Tw), added after each single-byte space character, in unscaled text space units.
ShowGlyphs(ReadOnlySpan<PdfGlyph>, string?)Shows glyphs at given positions with the current font (TJ), for a text that is already shaped and laid out: the glyphs are not shaped again. The font must be loaded from a font file (PdfFont.Load).
ShowText(ReadOnlySpan<PdfTextSegment>)Shows texts with individual adjustments of the positions of the glyphs (TJ), for kerning or justification.
ShowText(string)Shows a text with the current font (Tj).
ShowTextOnNextLine(string)Moves to the next line and shows a text (').
Stroke()Strokes the path (S).
Transform(PdfMatrix)Concatenates a matrix with the current transformation matrix (cm).
Translate(double, double)Moves the origin of the user space.

AppendRawContent(ReadOnlySpan<byte>)

PdfContentBuilder.cs

Appends content as it is, for operators the builder has no method for. The builder does not check it.

public PdfContentBuilder AppendRawContent(ReadOnlySpan<byte> content)

Parameters

content ReadOnlySpan<byte>
The content, in the syntax of content streams.

Returns

PdfContentBuilder The builder.

BeginArtifact(PdfArtifactType)

PdfContentBuilder.cs

Begins an artifact (/Artifact BDC, 14.8.2.2): content that is not part of the logical structure, such as a page number or a decoration, until the matching PdfContentBuilder.EndMarkedContent.

public PdfContentBuilder BeginArtifact(PdfArtifactType type = PdfArtifactType.Unspecified)

Parameters

type PdfArtifactType
The kind of artifact.

Returns

PdfContentBuilder The builder.

BeginMarkedContent overloads

BeginMarkedContent(string)

PdfContentBuilder.cs

Begins a marked-content sequence (BMC).

public PdfContentBuilder BeginMarkedContent(string tag)
Parameters
tag string
The tag, such as Span or Artifact.
Returns

PdfContentBuilder The builder.

BeginMarkedContent(string, PdfDictionary)

PdfContentBuilder.cs

Begins a marked-content sequence with a property list (BDC), such as <</MCID 0>>.

public PdfContentBuilder BeginMarkedContent(string tag, PdfDictionary properties)
Parameters
tag string
The tag.
properties PdfDictionary
The property list, written inline. It must not contain references.
Returns

PdfContentBuilder The builder.

BeginStructureElement(PdfStructureElement)

PdfContentBuilder.cs

Begins the marked content of an element of the structure tree (BDC with a marked-content identifier, ISO 32000-2, 14.7.5.2): the content until the matching PdfContentBuilder.EndMarkedContent belongs to the element.

public PdfContentBuilder BeginStructureElement(PdfStructureElement element)

Parameters

element PdfStructureElement
The element.

Returns

PdfContentBuilder The builder.

Exceptions

InvalidOperationException
The builder writes the content of a form or a pattern, not of a page.
ArgumentException
The element belongs to another document.

Begins a text object (BT): the text matrix is reset to the identity.

public PdfContentBuilder BeginText()

Returns

PdfContentBuilder The builder.

Exceptions

InvalidOperationException
A text object is already open.

Circle(double, double, double)

PdfContentBuilder.cs

Appends a circle as a closed subpath of four Bezier curves.

public PdfContentBuilder Circle(double centerX, double centerY, double radius)

Parameters

centerX double
The x coordinate of the center.
centerY double
The y coordinate of the center.
radius double
The radius.

Returns

PdfContentBuilder The builder.

Clip(PdfFillRule)

PdfContentBuilder.cs

Intersects the clipping path with the current path (W or W*); the path must then be painted or ended with PdfContentBuilder.EndPath.

public PdfContentBuilder Clip(PdfFillRule rule = PdfFillRule.NonZero)

Parameters

rule PdfFillRule
The fill rule that decides which points are inside the path.

Returns

PdfContentBuilder The builder.

CloseAndStroke()

PdfContentBuilder.cs

Closes and strokes the path (s).

public PdfContentBuilder CloseAndStroke()

Returns

PdfContentBuilder The builder.

CloseFillAndStroke(PdfFillRule)

PdfContentBuilder.cs

Closes, fills, then strokes the path (b or b*).

public PdfContentBuilder CloseFillAndStroke(PdfFillRule rule = PdfFillRule.NonZero)

Parameters

rule PdfFillRule
The fill rule.

Returns

PdfContentBuilder The builder.

Closes the current subpath with a straight line to its start (h).

public PdfContentBuilder ClosePath()

Returns

PdfContentBuilder The builder.

Checks that the content is balanced, and ends it: every PdfContentBuilder.SaveGraphicsState, PdfContentBuilder.BeginText and BeginMarkedContent call is matched. The builder cannot write anymore.

public void Complete()

Exceptions

InvalidOperationException
A text object, a saved graphics state or a marked-content sequence is still open. The builder can still write to close it.

Remarks

A content stream that leaves a graphics state saved or a marked-content sequence open changes the content that follows it: the content of the next builder of the page, or the pages that paint a form.

CurveTo(double, double, double, double, double, double)

PdfContentBuilder.cs

Appends a cubic Bezier curve (c).

public PdfContentBuilder CurveTo(double x1, double y1, double x2, double y2, double x3, double y3)

Parameters

x1 double
The x coordinate of the first control point.
y1 double
The y coordinate of the first control point.
x2 double
The x coordinate of the second control point.
y2 double
The y coordinate of the second control point.
x3 double
The x coordinate of the end point.
y3 double
The y coordinate of the end point.

Returns

PdfContentBuilder The builder.

CurveToEndPoint(double, double, double, double)

PdfContentBuilder.cs

Appends a cubic Bezier curve whose second control point is the end point (y).

public PdfContentBuilder CurveToEndPoint(double x1, double y1, double x3, double y3)

Parameters

x1 double
The x coordinate of the first control point.
y1 double
The y coordinate of the first control point.
x3 double
The x coordinate of the end point.
y3 double
The y coordinate of the end point.

Returns

PdfContentBuilder The builder.

CurveToFromCurrentPoint(double, double, double, double)

PdfContentBuilder.cs

Appends a cubic Bezier curve whose first control point is the current point (v).

public PdfContentBuilder CurveToFromCurrentPoint(double x2, double y2, double x3, double y3)

Parameters

x2 double
The x coordinate of the second control point.
y2 double
The y coordinate of the second control point.
x3 double
The x coordinate of the end point.
y3 double
The y coordinate of the end point.

Returns

PdfContentBuilder The builder.

DrawForm(PdfForm)

PdfContentBuilder.cs

Paints a form XObject (Do). The form is added to the resources.

public PdfContentBuilder DrawForm(PdfForm form)

Parameters

form PdfForm
The form, of the document of the builder.

Returns

PdfContentBuilder The builder.

Exceptions

ArgumentException
The form belongs to another document.

DrawImage(PdfImage, double, double, double, double)

PdfContentBuilder.cs

Draws an image in a rectangle of the user space: q, cm, Do, Q. The image is added to the resources.

public PdfContentBuilder DrawImage(PdfImage image, double x, double y, double width, double height)

Parameters

image PdfImage
The image.
x double
The x coordinate of the lower-left corner.
y double
The y coordinate of the lower-left corner.
width double
The width of the image on the page.
height double
The height of the image on the page.

Returns

PdfContentBuilder The builder.

DrawTable(PdfTable, PdfRectangle, PdfTableDrawResult?)

PdfContentBuilder.cs

Draws a table in a rectangle: the rows from the top of the rectangle, as many as fit in its height, with the borders, the backgrounds and the texts of the cells broken into lines. Call it again with the result to continue the table in another rectangle (on the next page): the header rows are drawn again at its top.

public PdfTableDrawResult DrawTable(PdfTable table, PdfRectangle rectangle, PdfTableDrawResult? previous = null)

Parameters

table PdfTable
The table.
rectangle PdfRectangle
The rectangle: the table starts at its top left corner, and the widths of its columns are computed from its width.
previous PdfTableDrawResult?
The result of the call that drew the previous part of the table, or null to draw it from the start.

Returns

PdfTableDrawResult Whether the whole table is drawn, the bottom of the part drawn, and where the next part starts.

Exceptions

ArgumentException
A character of a cell has no glyph in its font, the cells of a row span more columns than the table has, or previous is the result of a complete table. Nothing is drawn.
InvalidOperationException
The table has no column, or the rectangle is too small for the header rows and a line of the next row.

Remarks

A row that does not fit in the height left is drawn in the next rectangle, unless it is the first row of the rectangle after the header rows: the lines of its cells are then split between the rectangles. When the first rectangle has no room for a row, nothing is drawn and the table starts in the next one. The widths of the columns are computed once, and computed again only when the width of the rectangle changes, so that the columns of the parts are aligned.

DrawText(string, PdfFont, double, double, double)

PdfContentBuilder.cs

Shows a line of text at a position, in its own text object: BT, Tf, Td, Tj, ET.

public PdfContentBuilder DrawText(string text, PdfFont font, double fontSize, double x, double y)

Parameters

text string
The text.
font PdfFont
The font.
fontSize double
The font size.
x double
The x coordinate of the start of the baseline.
y double
The y coordinate of the baseline.

Returns

PdfContentBuilder The builder.

Exceptions

ArgumentException
A character of the text has no glyph in the font.

DrawTextBox overloads

DrawTextBox(string, PdfFont, double, PdfRectangle, PdfTextBoxOptions?)

PdfContentBuilder.cs

Draws a text in a rectangle, broken into lines that fit its width at the break opportunities of the Unicode line breaking algorithm (UAX #14): after the spaces and the hyphens, between ideographs. A word wider than the rectangle is broken between its characters. The line feeds of the text start new paragraphs. The lines that do not fit in the height of the rectangle are not drawn.

public PdfContentBuilder DrawTextBox(string text, PdfFont font, double fontSize, PdfRectangle rectangle, PdfTextBoxOptions? options = null)
Parameters
text string
The text.
font PdfFont
The font.
fontSize double
The font size.
rectangle PdfRectangle
The rectangle: the first baseline is below its top by the ascent of the font.
options PdfTextBoxOptions?
The alignment, the line height and the hyphenation, or null for the defaults.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
A character of the text has no glyph in the font. Nothing is drawn.

DrawTextBox(string, PdfFont, double, PdfRectangle, PdfTextBoxOptions?, string)

PdfContentBuilder.cs

Draws a text in a rectangle, broken into lines, and returns the text that does not fit, to draw it in another rectangle (the next column or page).

public PdfContentBuilder DrawTextBox(string text, PdfFont font, double fontSize, PdfRectangle rectangle, PdfTextBoxOptions? options, out string remainingText)
Parameters
text string
The text.
font PdfFont
The font.
fontSize double
The font size, more than 0.
rectangle PdfRectangle
The rectangle: the first baseline is below its top by the ascent of the font.
options PdfTextBoxOptions?
The alignment, the line height and the hyphenation, or null for the defaults.
remainingText string
The text of the lines that do not fit in the height of the rectangle, from the start of the first of them; empty when the whole text is drawn.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
A character of the text has no glyph in the font. Nothing is drawn.

Ellipse(double, double, double, double)

PdfContentBuilder.cs

Appends an ellipse as a closed subpath of four Bezier curves.

public PdfContentBuilder Ellipse(double centerX, double centerY, double radiusX, double radiusY)

Parameters

centerX double
The x coordinate of the center.
centerY double
The y coordinate of the center.
radiusX double
The horizontal radius.
radiusY double
The vertical radius.

Returns

PdfContentBuilder The builder.

EndMarkedContent()

PdfContentBuilder.cs

Ends the marked-content sequence of the matching BeginMarkedContent call (EMC).

public PdfContentBuilder EndMarkedContent()

Returns

PdfContentBuilder The builder.

Exceptions

InvalidOperationException
No marked-content sequence is open.

Ends the path without painting it (n), after PdfContentBuilder.Clip.

public PdfContentBuilder EndPath()

Returns

PdfContentBuilder The builder.

Ends the text object (ET).

public PdfContentBuilder EndText()

Returns

PdfContentBuilder The builder.

Exceptions

InvalidOperationException
No text object is open.

Fill(PdfFillRule)

PdfContentBuilder.cs

Fills the path (f or f*).

public PdfContentBuilder Fill(PdfFillRule rule = PdfFillRule.NonZero)

Parameters

rule PdfFillRule
The fill rule.

Returns

PdfContentBuilder The builder.

FillAndStroke(PdfFillRule)

PdfContentBuilder.cs

Fills, then strokes the path (B or B*).

public PdfContentBuilder FillAndStroke(PdfFillRule rule = PdfFillRule.NonZero)

Parameters

rule PdfFillRule
The fill rule.

Returns

PdfContentBuilder The builder.

LineTo(double, double)

PdfContentBuilder.cs

Appends a straight line to a point (l).

public PdfContentBuilder LineTo(double x, double y)

Parameters

x double
The x coordinate.
y double
The y coordinate.

Returns

PdfContentBuilder The builder.

MarkPoint overloads

MarkPoint(string)

PdfContentBuilder.cs

Marks a point of the content (MP).

public PdfContentBuilder MarkPoint(string tag)
Parameters
tag string
The tag.
Returns

PdfContentBuilder The builder.

MarkPoint(string, PdfDictionary)

PdfContentBuilder.cs

Marks a point of the content with a property list (DP).

public PdfContentBuilder MarkPoint(string tag, PdfDictionary properties)
Parameters
tag string
The tag.
properties PdfDictionary
The property list, written inline.
Returns

PdfContentBuilder The builder.

MoveTextPosition(double, double)

PdfContentBuilder.cs

Moves to the start of the next line, offset from the start of the current line (Td).

public PdfContentBuilder MoveTextPosition(double x, double y)

Parameters

x double
The horizontal offset.
y double
The vertical offset.

Returns

PdfContentBuilder The builder.

MoveTextPositionAndSetLeading(double, double)

PdfContentBuilder.cs

Moves to the start of the next line, offset from the start of the current line, and sets the leading to -y (TD).

public PdfContentBuilder MoveTextPositionAndSetLeading(double x, double y)

Parameters

x double
The horizontal offset.
y double
The vertical offset.

Returns

PdfContentBuilder The builder.

MoveTo(double, double)

PdfContentBuilder.cs

Begins a new subpath at a point (m).

public PdfContentBuilder MoveTo(double x, double y)

Parameters

x double
The x coordinate.
y double
The y coordinate.

Returns

PdfContentBuilder The builder.

MoveToNextLine()

PdfContentBuilder.cs

Moves to the start of the next line, using the leading (T*).

public PdfContentBuilder MoveToNextLine()

Returns

PdfContentBuilder The builder.

PaintShading(PdfShading)

PdfContentBuilder.cs

Paints a shading over the clipping region (sh). The shading is added to the resources.

public PdfContentBuilder PaintShading(PdfShading shading)

Parameters

shading PdfShading
The shading, in the current user space.

Returns

PdfContentBuilder The builder.

PaintXObject(string)

PdfContentBuilder.cs

Paints an external object of the resources by its name (Do).

public PdfContentBuilder PaintXObject(string name)

Parameters

name string
The name of the object in the /XObject resources.

Returns

PdfContentBuilder The builder.

Rectangle overloads

Rectangle(PdfRectangle)

PdfContentBuilder.cs

Appends a rectangle as a closed subpath (re).

public PdfContentBuilder Rectangle(PdfRectangle rectangle)
Parameters
rectangle PdfRectangle
The rectangle.
Returns

PdfContentBuilder The builder.

Rectangle(double, double, double, double)

PdfContentBuilder.cs

Appends a rectangle as a closed subpath (re).

public PdfContentBuilder Rectangle(double x, double y, double width, double height)
Parameters
x double
The x coordinate of a corner.
y double
The y coordinate of a corner.
width double
The width.
height double
The height.
Returns

PdfContentBuilder The builder.

RestoreGraphicsState()

PdfContentBuilder.cs

Restores the graphics state saved by the matching PdfContentBuilder.SaveGraphicsState call (Q).

public PdfContentBuilder RestoreGraphicsState()

Returns

PdfContentBuilder The builder.

Exceptions

InvalidOperationException
No graphics state is saved.

Rotate(double)

PdfContentBuilder.cs

Rotates the user space counterclockwise.

public PdfContentBuilder Rotate(double degrees)

Parameters

degrees double
The angle in degrees.

Returns

PdfContentBuilder The builder.

SaveGraphicsState()

PdfContentBuilder.cs

Saves the graphics state (q).

public PdfContentBuilder SaveGraphicsState()

Returns

PdfContentBuilder The builder.

Scale(double, double)

PdfContentBuilder.cs

Scales the user space.

public PdfContentBuilder Scale(double x, double y)

Parameters

x double
The horizontal scale.
y double
The vertical scale.

Returns

PdfContentBuilder The builder.

SetCharacterSpacing(double)

PdfContentBuilder.cs

Sets the character spacing (Tc), added after each glyph, in unscaled text space units.

public PdfContentBuilder SetCharacterSpacing(double spacing)

Parameters

spacing double
The spacing.

Returns

PdfContentBuilder The builder.

SetDashPattern(ReadOnlySpan<double>, double)

PdfContentBuilder.cs

Sets the dash pattern (d). An empty array draws solid lines.

public PdfContentBuilder SetDashPattern(ReadOnlySpan<double> dashArray, double phase = 0d)

Parameters

dashArray ReadOnlySpan<double>
The lengths of the dashes and the gaps, alternately.
phase double
The distance into the pattern at which the dashes start.

Returns

PdfContentBuilder The builder.

SetFillCmyk(double, double, double, double)

PdfContentBuilder.cs

Sets the nonstroking color in DeviceCMYK (k).

public PdfContentBuilder SetFillCmyk(double cyan, double magenta, double yellow, double black)

Parameters

cyan double
The cyan component, from 0 to 1.
magenta double
The magenta component, from 0 to 1.
yellow double
The yellow component, from 0 to 1.
black double
The black component, from 0 to 1.

Returns

PdfContentBuilder The builder.

SetFillColor(PdfColor)

PdfContentBuilder.cs

Sets the nonstroking color, used to fill paths and text (g, rg or k).

public PdfContentBuilder SetFillColor(PdfColor color)

Parameters

color PdfColor
The color.

Returns

PdfContentBuilder The builder.

SetFillColorComponents(ReadOnlySpan<double>)

PdfContentBuilder.cs

Sets the components of the nonstroking color in the current nonstroking color space (scn).

public PdfContentBuilder SetFillColorComponents(params scoped ReadOnlySpan<double> components)

Parameters

components ReadOnlySpan<double>
The components.

Returns

PdfContentBuilder The builder.

SetFillColorSpace(string)

PdfContentBuilder.cs

Sets the nonstroking color space (cs): a device color space name, or the name of a color space of the resources.

public PdfContentBuilder SetFillColorSpace(string colorSpace)

Parameters

colorSpace string
The name of the color space, such as DeviceRGB or Pattern.

Returns

PdfContentBuilder The builder.

SetFillGray(double)

PdfContentBuilder.cs

Sets the nonstroking color in DeviceGray (g).

public PdfContentBuilder SetFillGray(double gray)

Parameters

gray double
The gray level, from 0 (black) to 1 (white).

Returns

PdfContentBuilder The builder.

SetFillPattern overloads

SetFillPattern(PdfPattern)

PdfContentBuilder.cs

Sets a colored pattern as the nonstroking color (/Pattern cs, scn). The pattern is added to the resources.

public PdfContentBuilder SetFillPattern(PdfPattern pattern)
Parameters
pattern PdfPattern
The pattern: a shading pattern or a colored tiling pattern.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
The pattern is an uncolored tiling pattern, or it belongs to another document.

SetFillPattern(PdfTilingPattern, PdfColor)

PdfContentBuilder.cs

Sets an uncolored tiling pattern, painted with a color, as the nonstroking color. The pattern is added to the resources.

public PdfContentBuilder SetFillPattern(PdfTilingPattern pattern, PdfColor color)
Parameters
pattern PdfTilingPattern
The uncolored pattern.
color PdfColor
The color the cell is painted with.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
The pattern is colored, or it belongs to another document.

SetFillRgb(double, double, double)

PdfContentBuilder.cs

Sets the nonstroking color in DeviceRGB (rg).

public PdfContentBuilder SetFillRgb(double red, double green, double blue)

Parameters

red double
The red component, from 0 to 1.
green double
The green component, from 0 to 1.
blue double
The blue component, from 0 to 1.

Returns

PdfContentBuilder The builder.

SetFlatness(double)

PdfContentBuilder.cs

Sets the flatness tolerance (i).

public PdfContentBuilder SetFlatness(double flatness)

Parameters

flatness double
The tolerance, from 0 to 100.

Returns

PdfContentBuilder The builder.

SetFont(PdfFont, double)

PdfContentBuilder.cs

Sets the font and the font size (Tf). The font is added to the resources.

public PdfContentBuilder SetFont(PdfFont font, double size)

Parameters

font PdfFont
The font.
size double
The font size, in user space units.

Returns

PdfContentBuilder The builder.

SetGraphicsState(PdfExtGState)

PdfContentBuilder.cs

Sets the parameters of a graphics state parameter dictionary (gs), such as the transparency. The dictionary is added to the resources.

public PdfContentBuilder SetGraphicsState(PdfExtGState graphicsState)

Parameters

graphicsState PdfExtGState
The parameters.

Returns

PdfContentBuilder The builder.

SetHorizontalScaling(double)

PdfContentBuilder.cs

Sets the horizontal scaling of the glyphs (Tz), in percent.

public PdfContentBuilder SetHorizontalScaling(double percent)

Parameters

percent double
The scaling; 100 is the normal width.

Returns

PdfContentBuilder The builder.

SetLineCap(PdfLineCap)

PdfContentBuilder.cs

Sets the line cap style (J).

public PdfContentBuilder SetLineCap(PdfLineCap cap)

Parameters

cap PdfLineCap
The style.

Returns

PdfContentBuilder The builder.

SetLineJoin(PdfLineJoin)

PdfContentBuilder.cs

Sets the line join style (j).

public PdfContentBuilder SetLineJoin(PdfLineJoin join)

Parameters

join PdfLineJoin
The style.

Returns

PdfContentBuilder The builder.

SetLineWidth(double)

PdfContentBuilder.cs

Sets the line width (w).

public PdfContentBuilder SetLineWidth(double width)

Parameters

width double
The width, 0 or more.

Returns

PdfContentBuilder The builder.

SetMiterLimit(double)

PdfContentBuilder.cs

Sets the miter limit (M).

public PdfContentBuilder SetMiterLimit(double limit)

Parameters

limit double
The limit, 1 or more.

Returns

PdfContentBuilder The builder.

SetRenderingIntent(string)

PdfContentBuilder.cs

Sets the color rendering intent (ri), such as RelativeColorimetric or Perceptual.

public PdfContentBuilder SetRenderingIntent(string intent)

Parameters

intent string
The name of the intent.

Returns

PdfContentBuilder The builder.

SetStrokeCmyk(double, double, double, double)

PdfContentBuilder.cs

Sets the stroking color in DeviceCMYK (K).

public PdfContentBuilder SetStrokeCmyk(double cyan, double magenta, double yellow, double black)

Parameters

cyan double
The cyan component, from 0 to 1.
magenta double
The magenta component, from 0 to 1.
yellow double
The yellow component, from 0 to 1.
black double
The black component, from 0 to 1.

Returns

PdfContentBuilder The builder.

SetStrokeColor(PdfColor)

PdfContentBuilder.cs

Sets the stroking color (G, RG or K).

public PdfContentBuilder SetStrokeColor(PdfColor color)

Parameters

color PdfColor
The color.

Returns

PdfContentBuilder The builder.

SetStrokeColorComponents(ReadOnlySpan<double>)

PdfContentBuilder.cs

Sets the components of the stroking color in the current stroking color space (SCN).

public PdfContentBuilder SetStrokeColorComponents(params scoped ReadOnlySpan<double> components)

Parameters

components ReadOnlySpan<double>
The components.

Returns

PdfContentBuilder The builder.

SetStrokeColorSpace(string)

PdfContentBuilder.cs

Sets the stroking color space (CS): a device color space name, or the name of a color space of the resources.

public PdfContentBuilder SetStrokeColorSpace(string colorSpace)

Parameters

colorSpace string
The name of the color space, such as DeviceRGB or Pattern.

Returns

PdfContentBuilder The builder.

SetStrokeGray(double)

PdfContentBuilder.cs

Sets the stroking color in DeviceGray (G).

public PdfContentBuilder SetStrokeGray(double gray)

Parameters

gray double
The gray level, from 0 (black) to 1 (white).

Returns

PdfContentBuilder The builder.

SetStrokePattern overloads

SetStrokePattern(PdfPattern)

PdfContentBuilder.cs

Sets a colored pattern as the stroking color (/Pattern CS, SCN). The pattern is added to the resources.

public PdfContentBuilder SetStrokePattern(PdfPattern pattern)
Parameters
pattern PdfPattern
The pattern: a shading pattern or a colored tiling pattern.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
The pattern is an uncolored tiling pattern, or it belongs to another document.

SetStrokePattern(PdfTilingPattern, PdfColor)

PdfContentBuilder.cs

Sets an uncolored tiling pattern, painted with a color, as the stroking color. The pattern is added to the resources.

public PdfContentBuilder SetStrokePattern(PdfTilingPattern pattern, PdfColor color)
Parameters
pattern PdfTilingPattern
The uncolored pattern.
color PdfColor
The color the cell is painted with.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
The pattern is colored, or it belongs to another document.

SetStrokeRgb(double, double, double)

PdfContentBuilder.cs

Sets the stroking color in DeviceRGB (RG).

public PdfContentBuilder SetStrokeRgb(double red, double green, double blue)

Parameters

red double
The red component, from 0 to 1.
green double
The green component, from 0 to 1.
blue double
The blue component, from 0 to 1.

Returns

PdfContentBuilder The builder.

SetTextLeading(double)

PdfContentBuilder.cs

Sets the text leading (TL): the distance between the baselines of consecutive lines.

public PdfContentBuilder SetTextLeading(double leading)

Parameters

leading double
The leading, in unscaled text space units.

Returns

PdfContentBuilder The builder.

SetTextMatrix(PdfMatrix)

PdfContentBuilder.cs

Sets the text matrix and the text line matrix (Tm).

public PdfContentBuilder SetTextMatrix(PdfMatrix matrix)

Parameters

matrix PdfMatrix
The matrix.

Returns

PdfContentBuilder The builder.

SetTextRenderingMode(PdfTextRenderingMode)

PdfContentBuilder.cs

Sets the text rendering mode (Tr).

public PdfContentBuilder SetTextRenderingMode(PdfTextRenderingMode mode)

Parameters

mode PdfTextRenderingMode
The mode.

Returns

PdfContentBuilder The builder.

SetTextRise(double)

PdfContentBuilder.cs

Sets the text rise (Ts): the distance to move the baseline up (superscript) or down (subscript).

public PdfContentBuilder SetTextRise(double rise)

Parameters

rise double
The rise, in unscaled text space units.

Returns

PdfContentBuilder The builder.

SetWordSpacing(double)

PdfContentBuilder.cs

Sets the word spacing (Tw), added after each single-byte space character, in unscaled text space units.

public PdfContentBuilder SetWordSpacing(double spacing)

Parameters

spacing double
The spacing.

Returns

PdfContentBuilder The builder.

ShowGlyphs(ReadOnlySpan<PdfGlyph>, string?)

PdfContentBuilder.cs

Shows glyphs at given positions with the current font (TJ), for a text that is already shaped and laid out: the glyphs are not shaped again. The font must be loaded from a font file (PdfFont.Load).

public PdfContentBuilder ShowGlyphs(ReadOnlySpan<PdfGlyph> glyphs, string? text = null)

Parameters

glyphs ReadOnlySpan<PdfGlyph>
The glyphs, in the order they are painted, with the positions of their origins from the current text position.
text string?
The text the glyphs show, in logical order, or null when it is not known (the glyphs then cannot be extracted as text). When the glyphs do not show the characters of the text one after the other (a right-to-left run, a cluster of several glyphs), the text is their replacement text (/ActualText, ISO 32000-2, 14.9.4).

Returns

PdfContentBuilder The builder.

Exceptions

ArgumentOutOfRangeException
A glyph identifier is not a glyph of the font.
ArgumentException
A position is not a finite number.
InvalidOperationException
No text object is open, no font is set, the font is a standard font, or the font size is 0.

Remarks

The positions assume a character spacing of 0 and a horizontal scaling of 100: change the text matrix to scale the glyphs. After the call, the text position is after the advance of the last glyph.

ShowText overloads

ShowText(ReadOnlySpan<PdfTextSegment>)

PdfContentBuilder.cs

Shows texts with individual adjustments of the positions of the glyphs (TJ), for kerning or justification.

public PdfContentBuilder ShowText(params scoped ReadOnlySpan<PdfTextSegment> segments)
Parameters
segments ReadOnlySpan<PdfTextSegment>
The texts and the adjustments.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
A character of the text has no glyph in the font.
InvalidOperationException
No text object is open, or no font is set.

ShowText(string)

PdfContentBuilder.cs

Shows a text with the current font (Tj).

public PdfContentBuilder ShowText(string text)
Parameters
text string
The text.
Returns

PdfContentBuilder The builder.

Exceptions
ArgumentException
A character of the text has no glyph in the font.
InvalidOperationException
No text object is open, or no font is set.

ShowTextOnNextLine(string)

PdfContentBuilder.cs

Moves to the next line and shows a text (').

public PdfContentBuilder ShowTextOnNextLine(string text)

Parameters

text string
The text.

Returns

PdfContentBuilder The builder.

Exceptions

ArgumentException
A character of the text has no glyph in the font.
InvalidOperationException
No text object is open, or no font is set.

Strokes the path (S).

public PdfContentBuilder Stroke()

Returns

PdfContentBuilder The builder.

Transform(PdfMatrix)

PdfContentBuilder.cs

Concatenates a matrix with the current transformation matrix (cm).

public PdfContentBuilder Transform(PdfMatrix matrix)

Parameters

matrix PdfMatrix
The matrix.

Returns

PdfContentBuilder The builder.

Translate(double, double)

PdfContentBuilder.cs

Moves the origin of the user space.

public PdfContentBuilder Translate(double x, double y)

Parameters

x double
The horizontal translation.
y double
The vertical translation.

Returns

PdfContentBuilder The builder.