Skip to content

# PDFContentStream

Namespace: O2S.Components.PDF4NET.Graphics

Defines a low level graphics interface for drawing content on PDF pages.

    public class PDFContentStream

Inheritance Object → PDFContentStream

Remarks

The methods in this class match the PDF operators defined in the PDF specification.
A PDFContentStream object is created from a PDFCanvas object and lets you inject specific PDF operators in the PDFCanvas object, operators that are not available through the public API.
This class gives you full control over the generated page content but it requires good knowledge of PDF specification.

## Constructors

### PDFContentStream(PDFCanvas)

Initializes a new PDFContentStream object.

    public PDFContentStream(PDFCanvas graphics)

Parameters

`graphics` PDFCanvas
The PDFCanvas object associated with the content stream.

## Methods

### AddOperator(PDFContentStreamOperator)

Adds the given operator to the content stream.

    public void AddOperator(PDFContentStreamOperator op)

Parameters

`op` PDFContentStreamOperator
Operator to add to the content stream.

### BeginCompatibilitySection()

Begins a compatibility section.
Operator: BX.

    public void BeginCompatibilitySection()

### BeginInlineImage()

Begins an inline image.
Operator: BI.

    public void BeginInlineImage()

### BeginInlineImageData()

Begins the data section of an inline image.
Operator: ID.

    public void BeginInlineImageData()

### BeginMarkedContent(PDFCosName)

Begins a marked-content sequence.

    public void BeginMarkedContent(PDFCosName tag)

Parameters

`tag` PDFCosName
A name object indicating the role or significance of the sequence.

### BeginMarkedContentWithPropertyList(PDFCosName, PDFCosObject)

Begins a marked-content sequence with an associated property list.

    public void BeginMarkedContentWithPropertyList(PDFCosName tag, PDFCosObject properties)

Parameters

`tag` PDFCosName
A name object indicating the role or significance of the sequence.

`properties` PDFCosObject
Either an inline dictionary containing the property list or a name object associated with it in the Properties subdictionary of the current resource dictionary

### BeginText()

Begins a text section.
Operator: BT.

    public void BeginText()

### CCurveTo(Double, Double, Double, Double, Double, Double)

Append a cubic Bézier curve to the current path.
Operator: c

    public void CCurveTo(double x1, double y1, double x2, double y2, double x3, double y3)

Parameters

`x1` Double
X coordinate of the first control point.

`y1` Double
Y coordinate of the first control point.

`x2` Double
X coordinate of the second control point.

`y2` Double
Y coordinate of the second control point.

`x3` Double
X coordinate of the third control point.

`y3` Double
Y coordinate of the third control point.

Remarks

The curve extends from the current point to the point (x3, y3), using the (x1, y1) and (x2, y2) as the Bézier control points. The new current point is (x3, y3).

### Clear()

Clears the entire content stream.

    public void Clear()

Remarks

This method clears the graphic content stream including any markers inserted by PDF4NET library that are required by the graphics API. After this method has been called only the methods in this class should be used to build the graphic content. Using the API in the PDFCanvas class will lead to undefined results.

### CloseAndStrokePath()

Closes and strokes the current path.
Operator: s.

    public void CloseAndStrokePath()

### CloseFillNonZeroStroke(PDFFillMode)

Closes the current path, fills the path using the fillMode and then strokes the path.
Operator: b for PDFFillMode.NonZeroWinding or b* for PDFFillMode.EvenOdd.

    public void CloseFillNonZeroStroke(PDFFillMode fillMode)

Parameters

`fillMode` PDFFillMode
Path fill style.

### CloseSubpath()

Closes the current path.
Operator: h.

    public void CloseSubpath()

### ConcatenateMatrix(Double, Double, Double, Double, Double, Double)

Concatenates the given matrix with the current transformation matrix.
Operator: cm

    public void ConcatenateMatrix(double a, double b, double c, double d, double e, double f)

Parameters

`a` Double
First matrix element.

`b` Double
Second matrix element.

`c` Double
Third matrix element.

`d` Double
Fourth matrix element.

`e` Double
Fifth matrix element.

`f` Double
Sixth matrix element.

### DefineMarkedContentPoint(PDFCosName)

Defines a marked-content point.

    public void DefineMarkedContentPoint(PDFCosName tag)

Parameters

`tag` PDFCosName
A name object indicating the role or significance of the point.

### DefineMarkedContentPointWithPropertyList(PDFCosName, PDFCosObject)

Defines a marked-content point with an associated property list.

    public void DefineMarkedContentPointWithPropertyList(PDFCosName tag, PDFCosObject properties)

Parameters

`tag` PDFCosName
A name object indicating the role or significance of the point.

`properties` PDFCosObject
Either an inline dictionary containing the property list or a name object associated with it in the Properties subdictionary of the current resource dictionary

### EndCompatibilitySection()

Ends a compatibility section.
Operator: EX.

    public void EndCompatibilitySection()

### EndInlineImage()

Ends an inline image.
Operator: EI.

    public void EndInlineImage()

### EndMarkedContent()

Ends a marked content section.
Operator: EMC.

    public void EndMarkedContent()

### EndPath()

Ends the current path.
Operator: n.

    public void EndPath()

### EndText()

Ends a text section.
Operator: ET.

    public void EndText()

### FillNonZeroStroke(PDFFillMode)

Fills the current path using the fillMode and then strokes the path.
Operator: B for PDFFillMode.NonZeroWinding or B* for PDFFillMode.EvenOdd.

    public void FillNonZeroStroke(PDFFillMode fillMode)

Parameters

`fillMode` PDFFillMode
Path fill style.

### FillPath(PDFFillMode)

Fills the current path using the fillMode.
Operator: f for PDFFillMode.NonZeroWinding or f* for PDFFillMode.EvenOdd.

    public void FillPath(PDFFillMode fillMode)

Parameters

`fillMode` PDFFillMode
Path fill style.

### LineTo(Double, Double)

Appends a line segment to current path from current point to (x, y).
Operator: l

    public void LineTo(double x, double y)

Parameters

`x` Double
X coordinate of line end.

`y` Double
Y coordinate of line end.

Remarks

The (x, y) becomes the current point.

### MoveTextPosition(Double, Double)

Moves the text position.
Operator: Td

    public void MoveTextPosition(double tx, double ty)

Parameters

`tx` Double
X offset.

`ty` Double
Y offset.

Remarks

Moves to the start of the next line, offset from the start of the current line by (tx, ty).

### MoveTextPositionAndSetLeading(Double, Double)

Moves the text position.
Operator: TD

    public void MoveTextPositionAndSetLeading(double tx, double ty)

Parameters

`tx` Double
X offset.

`ty` Double
Y offset.

Remarks

Moves to the start of the next line, offset from the start of the current line by (tx, ty). Also sets the text leading to ty.

### MoveTo(Double, Double)

Begins a new subpath at (x, y).
Operator: m

    public void MoveTo(double x, double y)

Parameters

`x` Double
X coordinate of path start.

`y` Double
Y coordinate of path start.

Remarks

The (x, y) becomes the current point.

### MoveToStartOfNextTextLine()

Moves to the start of the next line.
Operator: T*

    public void MoveToStartOfNextTextLine()

### Rectangle(Double, Double, Double, Double)

Appends a rectangle to current path.
Operator: re

    public void Rectangle(double x, double y, double width, double height)

Parameters

`x` Double
X coordinate of the rectangle's bottom left corner.

`y` Double
Y coordinate of the rectangle's bottom left corner.

`width` Double
The rectangle width.

`height` Double
The rectangle height.

### ResetPDFCoordinateSystem()

Resets the coordinate system to default PDF coordinate system.

    public void ResetPDFCoordinateSystem()

Remarks

The PDF coordinate system is located in the bottom left corner of the page, the X axis grows from left to right, the Y axis grow from bottom to top.
The call to this method must be paired with a call to PDFContentStream.RestoreVisualCoordinateSystem().

### RestoreGraphicsState()

Restores the current graphics state.
Operator: Q.

    public void RestoreGraphicsState()

### RestoreVisualCoordinateSystem()

Restores the coordinate system as it has been setup initially by PDFCanvas class.

    public void RestoreVisualCoordinateSystem()

Remarks

The visual coordinate system is located in the top left corner of the page, the X axis grows from left to right, the Y axis grow from top to bottom.
This method must be called only if PDFContentStream.ResetPDFCoordinateSystem() or PDFContentStream.Clear() methods have been called before.

### SaveGraphicsState()

Saves the current graphics state.
Operator: q.

    public void SaveGraphicsState()

### SetCharacterSpacing(Double)

Sets the character spacing.
Operator: Tc

    public void SetCharacterSpacing(double characterSpacing)

Parameters

`characterSpacing` Double
The character spacing expressed in unscaled text space units.

### SetClipPath(PDFFillMode)

Sets the current path as clipping path.
Operator: W for PDFFillMode.NonZeroWinding or W* for PDFFillMode.EvenOdd.

    public void SetClipPath(PDFFillMode fillMode)

Parameters

`fillMode` PDFFillMode
Path fill style.

### SetCmykFillColor(Double, Double, Double, Double)

Sets the current colorspace for fill operations to DeviceCMYK and sets the current CMYK color.
Operator: k

    public void SetCmykFillColor(double c, double m, double y, double k)

Parameters

`c` Double
Cyan level.

`m` Double
Magenta level

`y` Double
Yellow level

`k` Double
Black level

### SetCmykStrokeColor(Double, Double, Double, Double)

Sets the current colorspace for stroke operations to DeviceCMYK and sets the current CMYK color.
Operator: K

    public void SetCmykStrokeColor(double c, double m, double y, double k)

Parameters

`c` Double
Cyan level.

`m` Double
Magenta level

`y` Double
Yellow level

`k` Double
Black level

### SetExtendedGraphicsState(PDFExtendedGraphicState)

Sets the current graphics state in the content stream.
Operator: gs

    public void SetExtendedGraphicsState(PDFExtendedGraphicState gs)

Parameters

`gs` PDFExtendedGraphicState
The new graphics state.

### SetFillColor(Double[])

Sets the current fill color.
Operator: sc

    public void SetFillColor(Double[] color)

Parameters

`color` Double[]
The color components.

Remarks

The number of color components in the array must match the number of color components expected by the active colorspace.

### SetFillColorN(Double[])

Sets the current fill color.
Operator: scn

    public void SetFillColorN(Double[] color)

Parameters

`color` Double[]
The color components.

Remarks

The number of color components in the array must match the number of color components expected by the active colorspace.

### SetFillColorN(PDFPattern)

Sets the current fill color.
Operator: scn

    public void SetFillColorN(PDFPattern pattern)

Parameters

`pattern` PDFPattern
The pattern used as fill color.

### SetFillColorN(Double[], PDFPattern)

Sets the current fill color and pattern.
Operator: scn

    public void SetFillColorN(Double[] color, PDFPattern pattern)

Parameters

`color` Double[]
The color components.

`pattern` PDFPattern
The pattern used as fill color.

Remarks

The number of color components in the array must match the number of color components expected by the active colorspace.

### SetFillColorSpace(PDFColorSpace)

Sets the fill colorspace.
Operator: cs

    public void SetFillColorSpace(PDFColorSpace colorSpace)

Parameters

`colorSpace` PDFColorSpace
The active colorspace used for fill operations

### SetFlatnessTolerance(Double)

Set the flatness tolerance in the graphics state.
Operator: i

    public void SetFlatnessTolerance(double flatness)

Parameters

`flatness` Double
The flatness tolerance.

### SetGrayFillColor(Double)

Sets the current colorspace for fill operations to DeviceGray and sets the gray level.
Operator: g

    public void SetGrayFillColor(double g)

Parameters

`g` Double
The gray level.

### SetGrayStrokeColor(Double)

Sets the current colorspace for stroke operations to DeviceGray and sets the gray level.
Operator: g

    public void SetGrayStrokeColor(double g)

Parameters

`g` Double
The gray level.

### SetLineCap(PDFLineCap)

Set the line cap style in the graphics state.
Operator: J

    public void SetLineCap(PDFLineCap lineCap)

Parameters

`lineCap` PDFLineCap
The line cap style.

### SetLineDashPattern(Double, Double[])

Sets the dash offset and pattern for stroke operations.
Operator: d

    public void SetLineDashPattern(double dashPhase, Double[] dashPattern)

Parameters

`dashPhase` Double
Dash phase.

`dashPattern` Double[]
Dash pattern.

### SetLineJoin(PDFLineJoin)

Set the line join style in the graphics state.
Operator: j

    public void SetLineJoin(PDFLineJoin lineJoin)

Parameters

`lineJoin` PDFLineJoin
The line join style.

### SetLineWidth(Double)

Sets the line width in the graphics state.

    public void SetLineWidth(double lineWidth)

Parameters

`lineWidth` Double
The line width

### SetMiterLimit(Double)

Set the miter limit in the graphics state.
Operator: M

    public void SetMiterLimit(double miterLimit)

Parameters

`miterLimit` Double
The miter limit.

### SetRgbFillColor(Double, Double, Double)

Sets the current colorspace for fill operations to DeviceRGB and sets the current RGB color.
Operator: rg

    public void SetRgbFillColor(double r, double g, double b)

Parameters

`r` Double
Red level.

`g` Double
Green level

`b` Double
Blue level

Remarks

The r, g, b values are in (0, 1) range.

### SetRgbStrokeColor(Double, Double, Double)

Sets the current colorspace for stroke operations to DeviceRGB and sets the current RGB color.
Operator: RG

    public void SetRgbStrokeColor(double r, double g, double b)

Parameters

`r` Double
Red level.

`g` Double
Green level

`b` Double
Blue level

Remarks

The r, g, b values are in (0, 1) range.

### SetStrokeColor(Double[])

Sets the current stroke color.
Operator: SC

    public void SetStrokeColor(Double[] color)

Parameters

`color` Double[]
The color components.

Remarks

The number of color components in the array must match the number of color components expected by the active colorspace.

### SetStrokeColorN(Double[])

Sets the current stroke color.
Operator: SCN

    public void SetStrokeColorN(Double[] color)

Parameters

`color` Double[]
The color components.

Remarks

The number of color components in the array must match the number of color components expected by the active colorspace.

### SetStrokeColorN(PDFPattern)

Sets the current stroke color.
Operator: scn

    public void SetStrokeColorN(PDFPattern pattern)

Parameters

`pattern` PDFPattern
The pattern used as stroke color.

### SetStrokeColorN(Double[], PDFPattern)

Sets the current stroke color and pattern.
Operator: SCN

    public void SetStrokeColorN(Double[] color, PDFPattern pattern)

Parameters

`color` Double[]
The color components.

`pattern` PDFPattern
The pattern used as fill color.

Remarks

The number of color components in the array must match the number of color components expected by the active colorspace.

### SetStrokeColorSpace(PDFColorSpace)

Sets the stroke colorspace.
Operator: CS

    public void SetStrokeColorSpace(PDFColorSpace colorSpace)

Parameters

`colorSpace` PDFColorSpace
The active colorspace used for stroke operations

### SetTextFontAndSize(PDFFont, Double)

Sets the current font and size for text show operators.
Operator: Tf

    public void SetTextFontAndSize(PDFFont font, double size)

Parameters

`font` PDFFont
Current font.

`size` Double
Current font size.

### SetTextHorizontalScaling(Double)

Sets the text horizontal scaling.
Operator: Tz

    public void SetTextHorizontalScaling(double horizontalScaling)

Parameters

`horizontalScaling` Double
Horizontal scaling specified as a percentage of normal width.

### SetTextLeading(Double)

Sets the text leading.
Operator: TL

    public void SetTextLeading(double textLeading)

Parameters

`textLeading` Double
The text leading expressed in unscaled text space units.

### SetTextMatrix(Double, Double, Double, Double, Double, Double)

Sets the current text matrix and text line matrix.
Operator: Tm

    public void SetTextMatrix(double a, double b, double c, double d, double e, double f)

Parameters

`a` Double
First matrix element.

`b` Double
Second matrix element.

`c` Double
Third matrix element.

`d` Double
Fourth matrix element.

`e` Double
Fifth matrix element.

`f` Double
Sixth matrix element.

### SetTextRendering(PDFTextRenderingMode)

Sets the text rendering mode.
Operator: Tr

    public void SetTextRendering(PDFTextRenderingMode textRenderingMode)

Parameters

`textRenderingMode` PDFTextRenderingMode
Text rendering mode.

### SetTextRise(Double)

Sets the text rise.
Operator: Ts

    public void SetTextRise(double textRise)

Parameters

`textRise` Double
The text rise expressed in unscaled text space units.

### SetWordSpacing(Double)

Sets the word spacing.
Operator: Tw

    public void SetWordSpacing(double wordSpacing)

Parameters

`wordSpacing` Double
The word spacing expressed in unscaled text space units.

### ShowFormXObject(PDFFormXObject)

Shows a form XObject on the page.
Operator: Do

    public void ShowFormXObject(PDFFormXObject xObject)

Parameters

`xObject` PDFFormXObject
Form XObject to display.

### ShowImage(PDFImage)

Shows an image on the page.
Operator: Do

    public void ShowImage(PDFImage image)

Parameters

`image` PDFImage
Image to display.

### ShowShading(PDFShading)

Shows a shading on the page.
Operator: sh

    public void ShowShading(PDFShading sh)

Parameters

`sh` PDFShading
Shading to display.

### ShowText(PDFCosBinaryString)

Shows the specified text on the page.
Operator: Tj

    public void ShowText(PDFCosBinaryString text)

Parameters

`text` PDFCosBinaryString
Text to show on the page.

### ShowTextArray(PDFCosArray)

Shows one or more text strings, allowing individual glyph positioning.

    public void ShowTextArray(PDFCosArray textArray)

Parameters

`textArray` PDFCosArray
Array of text strings.

Remarks

Each element of textArray can be a string or a number. If the element is a string, this operator shows the string. If it is a number, the operator adjusts the text position by that amount.

### StrokePath()

Strokes the current path.
Operator: S.

    public void StrokePath()

### VCurveTo(Double, Double, Double, Double)

Append a cubic Bézier curve to the current path.
Operator: v

    public void VCurveTo(double x2, double y2, double x3, double y3)

Parameters

`x2` Double
X coordinate of second control point.

`y2` Double
Y coordinate of second control point.

`x3` Double
X coordinate of curve end point.

`y3` Double
Y coordinate of curve end point.

Remarks

The curve extends from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bézier control points. The new current point is (x3, y3).

### WriteByte(Byte)

Writes the specified byte to the content stream.

    public void WriteByte(byte b)

Parameters

`b` Byte
Byte to write.

Remarks

This method is usefull to create new lines in the content stream.

### WriteBytes(Byte[])

Writes the specified bytes to the content stream.

    public void WriteBytes(Byte[] buffer)

Parameters

`buffer` Byte[]
Bytes to write.

Remarks

This method is usefull to write the data of an inline image to the content stream.

### WriteBytes(Byte[], Int32, Int32)

Writes the specified bytes to the content stream.

    public void WriteBytes(Byte[] buffer, int offset, int count)

Parameters

`buffer` Byte[]
Bytes to write.

`offset` Int32
Offset in the buffer were the bytes to write start.

`count` Int32
Number of bytes to write.

Remarks

This method is usefull to write the data of an inline image to the content stream.

### YCurveTo(Double, Double, Double, Double)

Append a cubic Bézier curve to the current path.
Operator: y

    public void YCurveTo(double x1, double y1, double x3, double y3)

Parameters

`x1` Double
X coordinate of first control point.

`y1` Double
Y coordinate of first control point.

`x3` Double
X coordinate of curve end point.

`y3` Double
Y coordinate of curve end point.

Remarks

The curve extends from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bézier control points. The new current point is (x3, y3).