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 PdfContentBuilderRemarks
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
| Name | Description |
|---|---|
| GraphicsStateDepth | Gets the number of PdfContentBuilder.SaveGraphicsState calls that are not matched by a PdfContentBuilder.RestoreGraphicsState call. |
| IsInTextObject | Gets a value indicating whether a text object is open: PdfContentBuilder.BeginText was called, and PdfContentBuilder.EndText was not. |
| MarkedContentDepth | Gets the number of BeginMarkedContent, PdfContentBuilder.BeginStructureElement and PdfContentBuilder.BeginArtifact calls that are not matched by an PdfContentBuilder.EndMarkedContent call. |
GraphicsStateDepth
PdfContentBuilder.csGets the number of PdfContentBuilder.SaveGraphicsState calls that are not matched by a PdfContentBuilder.RestoreGraphicsState call.
public int GraphicsStateDepth { get; }Property value
IsInTextObject
PdfContentBuilder.csGets a value indicating whether a text object is open: PdfContentBuilder.BeginText was called, and PdfContentBuilder.EndText was not.
public bool IsInTextObject { get; }Property value
MarkedContentDepth
PdfContentBuilder.csGets 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
Methods
| Name | Description |
|---|---|
| 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.csAppends 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
contentReadOnlySpan<byte>- The content, in the syntax of content streams.
Returns
PdfContentBuilder The builder.
BeginArtifact(PdfArtifactType)
PdfContentBuilder.csBegins 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)BeginMarkedContent overloads
BeginMarkedContent(string)
PdfContentBuilder.csBegins a marked-content sequence (BMC).
public PdfContentBuilder BeginMarkedContent(string tag)BeginMarkedContent(string, PdfDictionary)
PdfContentBuilder.csBegins a marked-content sequence with a property list (BDC), such as <</MCID 0>>.
public PdfContentBuilder BeginMarkedContent(string tag, PdfDictionary properties)Parameters
tagstring- The tag.
propertiesPdfDictionary- The property list, written inline. It must not contain references.
Returns
PdfContentBuilder The builder.
BeginStructureElement(PdfStructureElement)
PdfContentBuilder.csBegins 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
elementPdfStructureElement- 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.
BeginText()
PdfContentBuilder.csBegins 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.csAppends a circle as a closed subpath of four Bezier curves.
public PdfContentBuilder Circle(double centerX, double centerY, double radius)Parameters
centerXdouble- The x coordinate of the center.
centerYdouble- The y coordinate of the center.
radiusdouble- The radius.
Returns
PdfContentBuilder The builder.
Clip(PdfFillRule)
PdfContentBuilder.csIntersects 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
rulePdfFillRule- The fill rule that decides which points are inside the path.
Returns
PdfContentBuilder The builder.
CloseAndStroke()
PdfContentBuilder.csCloses and strokes the path (s).
public PdfContentBuilder CloseAndStroke()Returns
PdfContentBuilder The builder.
CloseFillAndStroke(PdfFillRule)
PdfContentBuilder.csCloses, fills, then strokes the path (b or b*).
public PdfContentBuilder CloseFillAndStroke(PdfFillRule rule = PdfFillRule.NonZero)ClosePath()
PdfContentBuilder.csCloses the current subpath with a straight line to its start (h).
public PdfContentBuilder ClosePath()Returns
PdfContentBuilder The builder.
Complete()
PdfContentBuilder.csChecks 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.csAppends a cubic Bezier curve (c).
Parameters
x1double- The x coordinate of the first control point.
y1double- The y coordinate of the first control point.
x2double- The x coordinate of the second control point.
y2double- The y coordinate of the second control point.
x3double- The x coordinate of the end point.
y3double- The y coordinate of the end point.
Returns
PdfContentBuilder The builder.
CurveToEndPoint(double, double, double, double)
PdfContentBuilder.csAppends 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
x1double- The x coordinate of the first control point.
y1double- The y coordinate of the first control point.
x3double- The x coordinate of the end point.
y3double- The y coordinate of the end point.
Returns
PdfContentBuilder The builder.
CurveToFromCurrentPoint(double, double, double, double)
PdfContentBuilder.csAppends 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
x2double- The x coordinate of the second control point.
y2double- The y coordinate of the second control point.
x3double- The x coordinate of the end point.
y3double- The y coordinate of the end point.
Returns
PdfContentBuilder The builder.
DrawForm(PdfForm)
PdfContentBuilder.csPaints a form XObject (Do). The form is added to the resources.
public PdfContentBuilder DrawForm(PdfForm form)Parameters
formPdfForm- 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.csDraws an image in a rectangle of the user space: q, cm, Do, Q. The image is added to the resources.
DrawTable(PdfTable, PdfRectangle, PdfTableDrawResult?)
PdfContentBuilder.csDraws 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
tablePdfTable- The table.
rectanglePdfRectangle- The rectangle: the table starts at its top left corner, and the widths of its columns are computed from its width.
previousPdfTableDrawResult?- The result of the call that drew the previous part of the table, or
nullto 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
previousis 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.csShows a line of text at a position, in its own text object: BT, Tf, Td, Tj, ET.
Parameters
textstring- The text.
fontPdfFont- The font.
fontSizedouble- The font size.
xdouble- The x coordinate of the start of the baseline.
ydouble- 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.csDraws 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
textstring- The text.
fontPdfFont- The font.
fontSizedouble- The font size.
rectanglePdfRectangle- The rectangle: the first baseline is below its top by the ascent of the font.
optionsPdfTextBoxOptions?- The alignment, the line height and the hyphenation, or
nullfor 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.csDraws 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
textstring- The text.
fontPdfFont- The font.
fontSizedouble- The font size, more than 0.
rectanglePdfRectangle- The rectangle: the first baseline is below its top by the ascent of the font.
optionsPdfTextBoxOptions?- The alignment, the line height and the hyphenation, or
nullfor the defaults. remainingTextstring- 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.csAppends an ellipse as a closed subpath of four Bezier curves.
public PdfContentBuilder Ellipse(double centerX, double centerY, double radiusX, double radiusY)Parameters
centerXdouble- The x coordinate of the center.
centerYdouble- The y coordinate of the center.
radiusXdouble- The horizontal radius.
radiusYdouble- The vertical radius.
Returns
PdfContentBuilder The builder.
EndMarkedContent()
PdfContentBuilder.csEnds 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.
EndPath()
PdfContentBuilder.csEnds the path without painting it (n), after PdfContentBuilder.Clip.
public PdfContentBuilder EndPath()Returns
PdfContentBuilder The builder.
EndText()
PdfContentBuilder.csEnds the text object (ET).
public PdfContentBuilder EndText()Fill(PdfFillRule)
PdfContentBuilder.csFills the path (f or f*).
public PdfContentBuilder Fill(PdfFillRule rule = PdfFillRule.NonZero)FillAndStroke(PdfFillRule)
PdfContentBuilder.csFills, then strokes the path (B or B*).
public PdfContentBuilder FillAndStroke(PdfFillRule rule = PdfFillRule.NonZero)LineTo(double, double)
PdfContentBuilder.csAppends a straight line to a point (l).
public PdfContentBuilder LineTo(double x, double y)MarkPoint overloads
MarkPoint(string)
PdfContentBuilder.csMarks a point of the content (MP).
public PdfContentBuilder MarkPoint(string tag)MarkPoint(string, PdfDictionary)
PdfContentBuilder.csMarks a point of the content with a property list (DP).
public PdfContentBuilder MarkPoint(string tag, PdfDictionary properties)Parameters
tagstring- The tag.
propertiesPdfDictionary- The property list, written inline.
Returns
PdfContentBuilder The builder.
MoveTextPosition(double, double)
PdfContentBuilder.csMoves to the start of the next line, offset from the start of the current line (Td).
public PdfContentBuilder MoveTextPosition(double x, double y)MoveTextPositionAndSetLeading(double, double)
PdfContentBuilder.csMoves 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)MoveTo(double, double)
PdfContentBuilder.csBegins a new subpath at a point (m).
public PdfContentBuilder MoveTo(double x, double y)MoveToNextLine()
PdfContentBuilder.csMoves to the start of the next line, using the leading (T*).
public PdfContentBuilder MoveToNextLine()Returns
PdfContentBuilder The builder.
PaintShading(PdfShading)
PdfContentBuilder.csPaints a shading over the clipping region (sh). The shading is added to the resources.
public PdfContentBuilder PaintShading(PdfShading shading)Parameters
shadingPdfShading- The shading, in the current user space.
Returns
PdfContentBuilder The builder.
PaintXObject(string)
PdfContentBuilder.csPaints an external object of the resources by its name (Do).
public PdfContentBuilder PaintXObject(string name)Parameters
namestring- The name of the object in the
/XObjectresources.
Returns
PdfContentBuilder The builder.
Rectangle overloads
Rectangle(PdfRectangle)
PdfContentBuilder.csAppends a rectangle as a closed subpath (re).
public PdfContentBuilder Rectangle(PdfRectangle rectangle)Rectangle(double, double, double, double)
PdfContentBuilder.csAppends a rectangle as a closed subpath (re).
public PdfContentBuilder Rectangle(double x, double y, double width, double height)Parameters
xdouble- The x coordinate of a corner.
ydouble- The y coordinate of a corner.
widthdouble- The width.
heightdouble- The height.
Returns
PdfContentBuilder The builder.
RestoreGraphicsState()
PdfContentBuilder.csRestores the graphics state saved by the matching PdfContentBuilder.SaveGraphicsState call (Q).
public PdfContentBuilder RestoreGraphicsState()Rotate(double)
PdfContentBuilder.csRotates the user space counterclockwise.
public PdfContentBuilder Rotate(double degrees)SaveGraphicsState()
PdfContentBuilder.csSaves the graphics state (q).
public PdfContentBuilder SaveGraphicsState()Returns
PdfContentBuilder The builder.
Scale(double, double)
PdfContentBuilder.csScales the user space.
public PdfContentBuilder Scale(double x, double y)SetCharacterSpacing(double)
PdfContentBuilder.csSets the character spacing (Tc), added after each glyph, in unscaled text space units.
public PdfContentBuilder SetCharacterSpacing(double spacing)SetDashPattern(ReadOnlySpan<double>, double)
PdfContentBuilder.csSets the dash pattern (d). An empty array draws solid lines.
public PdfContentBuilder SetDashPattern(ReadOnlySpan<double> dashArray, double phase = 0d)Parameters
dashArrayReadOnlySpan<double>- The lengths of the dashes and the gaps, alternately.
phasedouble- The distance into the pattern at which the dashes start.
Returns
PdfContentBuilder The builder.
SetFillCmyk(double, double, double, double)
PdfContentBuilder.csSets the nonstroking color in DeviceCMYK (k).
public PdfContentBuilder SetFillCmyk(double cyan, double magenta, double yellow, double black)Parameters
cyandouble- The cyan component, from 0 to 1.
magentadouble- The magenta component, from 0 to 1.
yellowdouble- The yellow component, from 0 to 1.
blackdouble- The black component, from 0 to 1.
Returns
PdfContentBuilder The builder.
SetFillColor(PdfColor)
PdfContentBuilder.csSets the nonstroking color, used to fill paths and text (g, rg or k).
public PdfContentBuilder SetFillColor(PdfColor color)SetFillColorComponents(ReadOnlySpan<double>)
PdfContentBuilder.csSets the components of the nonstroking color in the current nonstroking color space (scn).
public PdfContentBuilder SetFillColorComponents(params scoped ReadOnlySpan<double> components)SetFillColorSpace(string)
PdfContentBuilder.csSets 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
colorSpacestring- The name of the color space, such as
DeviceRGBorPattern.
Returns
PdfContentBuilder The builder.
SetFillGray(double)
PdfContentBuilder.csSets the nonstroking color in DeviceGray (g).
public PdfContentBuilder SetFillGray(double gray)Parameters
graydouble- The gray level, from 0 (black) to 1 (white).
Returns
PdfContentBuilder The builder.
SetFillPattern overloads
SetFillPattern(PdfPattern)
PdfContentBuilder.csSets a colored pattern as the nonstroking color (/Pattern cs, scn). The pattern is added to the resources.
public PdfContentBuilder SetFillPattern(PdfPattern pattern)Parameters
patternPdfPattern- 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.csSets 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
patternPdfTilingPattern- The uncolored pattern.
colorPdfColor- 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.csSets the nonstroking color in DeviceRGB (rg).
public PdfContentBuilder SetFillRgb(double red, double green, double blue)Parameters
reddouble- The red component, from 0 to 1.
greendouble- The green component, from 0 to 1.
bluedouble- The blue component, from 0 to 1.
Returns
PdfContentBuilder The builder.
SetFlatness(double)
PdfContentBuilder.csSets the flatness tolerance (i).
public PdfContentBuilder SetFlatness(double flatness)SetFont(PdfFont, double)
PdfContentBuilder.csSets the font and the font size (Tf). The font is added to the resources.
public PdfContentBuilder SetFont(PdfFont font, double size)SetGraphicsState(PdfExtGState)
PdfContentBuilder.csSets 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)SetHorizontalScaling(double)
PdfContentBuilder.csSets the horizontal scaling of the glyphs (Tz), in percent.
public PdfContentBuilder SetHorizontalScaling(double percent)SetLineCap(PdfLineCap)
PdfContentBuilder.csSets the line cap style (J).
public PdfContentBuilder SetLineCap(PdfLineCap cap)SetLineJoin(PdfLineJoin)
PdfContentBuilder.csSets the line join style (j).
public PdfContentBuilder SetLineJoin(PdfLineJoin join)SetLineWidth(double)
PdfContentBuilder.csSets the line width (w).
public PdfContentBuilder SetLineWidth(double width)SetMiterLimit(double)
PdfContentBuilder.csSets the miter limit (M).
public PdfContentBuilder SetMiterLimit(double limit)SetRenderingIntent(string)
PdfContentBuilder.csSets the color rendering intent (ri), such as RelativeColorimetric or Perceptual.
public PdfContentBuilder SetRenderingIntent(string intent)SetStrokeCmyk(double, double, double, double)
PdfContentBuilder.csSets the stroking color in DeviceCMYK (K).
public PdfContentBuilder SetStrokeCmyk(double cyan, double magenta, double yellow, double black)Parameters
cyandouble- The cyan component, from 0 to 1.
magentadouble- The magenta component, from 0 to 1.
yellowdouble- The yellow component, from 0 to 1.
blackdouble- The black component, from 0 to 1.
Returns
PdfContentBuilder The builder.
SetStrokeColor(PdfColor)
PdfContentBuilder.csSets the stroking color (G, RG or K).
public PdfContentBuilder SetStrokeColor(PdfColor color)SetStrokeColorComponents(ReadOnlySpan<double>)
PdfContentBuilder.csSets the components of the stroking color in the current stroking color space (SCN).
public PdfContentBuilder SetStrokeColorComponents(params scoped ReadOnlySpan<double> components)SetStrokeColorSpace(string)
PdfContentBuilder.csSets 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
colorSpacestring- The name of the color space, such as
DeviceRGBorPattern.
Returns
PdfContentBuilder The builder.
SetStrokeGray(double)
PdfContentBuilder.csSets the stroking color in DeviceGray (G).
public PdfContentBuilder SetStrokeGray(double gray)Parameters
graydouble- The gray level, from 0 (black) to 1 (white).
Returns
PdfContentBuilder The builder.
SetStrokePattern overloads
SetStrokePattern(PdfPattern)
PdfContentBuilder.csSets a colored pattern as the stroking color (/Pattern CS, SCN). The pattern is added to the resources.
public PdfContentBuilder SetStrokePattern(PdfPattern pattern)Parameters
patternPdfPattern- 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.csSets 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
patternPdfTilingPattern- The uncolored pattern.
colorPdfColor- 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.csSets the stroking color in DeviceRGB (RG).
public PdfContentBuilder SetStrokeRgb(double red, double green, double blue)Parameters
reddouble- The red component, from 0 to 1.
greendouble- The green component, from 0 to 1.
bluedouble- The blue component, from 0 to 1.
Returns
PdfContentBuilder The builder.
SetTextLeading(double)
PdfContentBuilder.csSets the text leading (TL): the distance between the baselines of consecutive lines.
public PdfContentBuilder SetTextLeading(double leading)Parameters
leadingdouble- The leading, in unscaled text space units.
Returns
PdfContentBuilder The builder.
SetTextMatrix(PdfMatrix)
PdfContentBuilder.csSets the text matrix and the text line matrix (Tm).
public PdfContentBuilder SetTextMatrix(PdfMatrix matrix)SetTextRenderingMode(PdfTextRenderingMode)
PdfContentBuilder.csSets the text rendering mode (Tr).
public PdfContentBuilder SetTextRenderingMode(PdfTextRenderingMode mode)SetTextRise(double)
PdfContentBuilder.csSets the text rise (Ts): the distance to move the baseline up (superscript) or down (subscript).
public PdfContentBuilder SetTextRise(double rise)SetWordSpacing(double)
PdfContentBuilder.csSets the word spacing (Tw), added after each single-byte space character, in unscaled text space units.
public PdfContentBuilder SetWordSpacing(double spacing)ShowGlyphs(ReadOnlySpan<PdfGlyph>, string?)
PdfContentBuilder.csShows 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
glyphsReadOnlySpan<PdfGlyph>- The glyphs, in the order they are painted, with the positions of their origins from the current text position.
textstring?- The text the glyphs show, in logical order, or
nullwhen 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.csShows texts with individual adjustments of the positions of the glyphs (TJ), for kerning or justification.
public PdfContentBuilder ShowText(params scoped ReadOnlySpan<PdfTextSegment> segments)Parameters
segmentsReadOnlySpan<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.csShows a text with the current font (Tj).
public PdfContentBuilder ShowText(string text)Parameters
textstring- 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.csMoves to the next line and shows a text (').
public PdfContentBuilder ShowTextOnNextLine(string text)Parameters
textstring- 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.
Stroke()
PdfContentBuilder.csTransform(PdfMatrix)
PdfContentBuilder.csConcatenates a matrix with the current transformation matrix (cm).
public PdfContentBuilder Transform(PdfMatrix matrix)Translate(double, double)
PdfContentBuilder.csMoves the origin of the user space.
public PdfContentBuilder Translate(double x, double y)