Class ContentStreamWriter
- Namespace
- SoftZenPdf
- Assembly
- SoftZenPdf.dll
Draws on a page by writing PDF content-stream operators. Obtain it from Content; every method returns the writer so calls can be chained.
public sealed class ContentStreamWriter
- Inheritance
-
ContentStreamWriter
- Inherited Members
Remarks
The high-level methods (DrawText(string, double, double, PdfFont, double, PdfColor?), DrawLine(double, double, double, double, PdfColor?, double), DrawRectangle(double, double, double, double, PdfColor?, PdfColor?, double), DrawEllipse(double, double, double, double, PdfColor?, PdfColor?, double), DrawCircle(double, double, double, PdfColor?, PdfColor?, double), DrawImage(PdfImage, double, double, double, double)) save and restore the graphics state themselves, so their colours and line widths do not leak into later drawing. The low-level methods map one-to-one onto PDF operators (ISO 32000-1 §8 and §9) for paths, transforms and text objects.
Coordinates are points (1/72 inch) from the bottom-left corner of the page, unless changed with Transform(double, double, double, double, double, double). Operator order is checked as you go: text operators outside a text object and path operators inside one throw InvalidOperationException.
Properties
- IsInTextObject
Whether a text object is open: BeginText() has been called without a matching EndText().
- StateDepth
How many SaveState() calls have not yet been matched by RestoreState().
- TextDirection
The base direction used to order mixed left-to-right and right-to-left text in ShowText(string) and DrawText(string, double, double, PdfFont, double, PdfColor?). Defaults to Auto. It is not part of the graphics state, so RestoreState() does not reset it.
Methods
- BeginText()
Opens a text object (operator
BT); close it with EndText().
- ClosePath()
Closes the current subpath with a straight line back to its start (operator
h).
- CurveTo(double, double, double, double, double, double)
Adds a cubic Bézier curve from the current point (operator
c).
- DrawCircle(double, double, double, PdfColor?, PdfColor?, double)
Draws a circle, filled, outlined or both.
- DrawEllipse(double, double, double, double, PdfColor?, PdfColor?, double)
Draws an ellipse, filled, outlined or both.
- DrawImage(PdfImage, double, double, double)
Draws an image at a given width, with the height following its aspect ratio.
- DrawImage(PdfImage, double, double, double, double)
Draws an image stretched to fill a box. EXIF (JPEG) and TIFF orientation is applied, so photos and scans appear upright.
- DrawLine(double, double, double, double, PdfColor?, double)
Draws a straight line.
- DrawRectangle(double, double, double, double, PdfColor?, PdfColor?, double)
Draws a rectangle, filled, outlined or both.
- DrawText(string, double, double, PdfFont, double, PdfColor?)
Draws a single line of text with its baseline starting at (x, y). Text is not wrapped.
- Ellipse(double, double, double, double)
Adds an ellipse as a closed subpath made of four Bézier curves.
- EndText()
Closes the text object opened by BeginText() (operator
ET).
- Fill()
Fills the current path with the fill colour using the non-zero winding rule, then ends it (operator
f).
- FillAndStroke()
Fills and then strokes the current path, then ends it (operator
B).
- LineTo(double, double)
Adds a straight line from the current point to a new point (operator
l).
- MoveTextPosition(double, double)
Moves to the start of the next line, offset from the start of the current line (operator
Td). The first call in a text object positions the text at (tx,ty) on the page.
- MoveTo(double, double)
Starts a new subpath at a point (operator
m).
- Rectangle(double, double, double, double)
Adds a rectangle as a closed subpath (operator
re).
- RestoreState()
Restores the graphics state saved by the matching SaveState(). Operator
Q.
- SaveState()
Saves the graphics state (colours, line width, opacity, transform, clipping) so that it can be restored with RestoreState(). Operator
q.
- SetFillColor(PdfColor)
Sets the RGB colour used to fill shapes and text (operator
rg).
- SetFont(PdfFont, double)
Selects the font and size for following text (operator
Tf).
- SetLineWidth(double)
Sets the width of stroked lines, in points (operator
w).
- SetOpacity(double)
Sets the same opacity for filling and stroking. See SetOpacity(double, double).
- SetOpacity(double, double)
Sets the opacity of later fills and strokes through an ExtGState resource (operator
gs). Wrap it in SaveState()/RestoreState() to limit its effect.
- SetStrokeColor(PdfColor)
Sets the RGB colour used to stroke lines and outlines (operator
RG).
- SetTextMatrix(double, double, double, double, double, double)
Sets the text matrix, which places and orients the following text (operator
Tm). Use it inside a text object instead of MoveTextPosition(double, double) to draw rotated or scaled text.
- SetTextRenderingMode(TextRenderingMode)
Sets how glyphs are painted (operator
Tr): filled (the default), outlined, both, or invisible, which keeps text searchable and copyable without showing it (as in a text layer over a scanned image). Stroking uses the stroke colour and line width. Like the font, it is part of the graphics state.
- ShowText(string)
Shows a line of text at the current text position in the current font (operator
Tj, orTJwhen kerning or mark positioning adjusts the spacing, with text riseTsfor raised or lowered marks). Right-to-left and mixed-direction text is reordered for display with the Unicode Bidirectional Algorithm, TrueType text is shaped with the font's substitutions (such as joined Arabic letters and ligatures), and where the glyphs no longer read as the text, it is marked with its reading order (ActualText) so that it copies and extracts correctly.
- Stroke()
Strokes the current path with the stroke colour and line width, then ends it (operator
S).
- ToArray()
Returns the raw, uncompressed content-stream bytes written so far.
- Transform(double, double, double, double, double, double)
Multiplies the current transformation matrix by [a b c d e f], changing how later coordinates map onto the page. Operator
cm. Wrap it in SaveState()/RestoreState() to limit its effect.