PDFContentStream¶
Namespace: O2S.Components.PDF4NET.Graphics
Defines a low level graphics interface for drawing content on PDF pages.
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.
Parameters
graphics PDFCanvas
The PDFCanvas object associated with the content stream.
Methods¶
AddOperator(PDFContentStreamOperator)¶
Adds the given operator to the content stream.
Parameters
op PDFContentStreamOperator
Operator to add to the content stream.
BeginCompatibilitySection()¶
Begins a compatibility section.
Operator: BX.
BeginInlineImage()¶
Begins an inline image.
Operator: BI.
BeginInlineImageData()¶
Begins the data section of an inline image.
Operator: ID.
BeginMarkedContent(PDFCosName)¶
Begins a marked-content sequence.
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.
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.
CCurveTo(Double, Double, Double, Double, Double, Double)¶
Append a cubic Bézier curve to the current path.
Operator: c
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.
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.
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.
Parameters
fillMode PDFFillMode
Path fill style.
CloseSubpath()¶
Closes the current path.
Operator: h.
ConcatenateMatrix(Double, Double, Double, Double, Double, Double)¶
Concatenates the given matrix with the current transformation matrix.
Operator: cm
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.
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.
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.
EndInlineImage()¶
Ends an inline image.
Operator: EI.
EndMarkedContent()¶
Ends a marked content section.
Operator: EMC.
EndPath()¶
Ends the current path.
Operator: n.
EndText()¶
Ends a text section.
Operator: ET.
FillNonZeroStroke(PDFFillMode)¶
Fills the current path using the fillMode and then strokes the path.
Operator: B for PDFFillMode.NonZeroWinding or B* for PDFFillMode.EvenOdd.
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.
Parameters
fillMode PDFFillMode
Path fill style.
LineTo(Double, Double)¶
Appends a line segment to current path from current point to (x, y).
Operator: l
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
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
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
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*
Rectangle(Double, Double, Double, Double)¶
Appends a rectangle to current path.
Operator: re
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.
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.
RestoreVisualCoordinateSystem()¶
Restores the coordinate system as it has been setup initially by PDFCanvas class.
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.
SetCharacterSpacing(Double)¶
Sets the character spacing.
Operator: Tc
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.
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
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
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
Parameters
gs PDFExtendedGraphicState
The new graphics state.
SetFillColor(Double[])¶
Sets the current fill color.
Operator: sc
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
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
Parameters
pattern PDFPattern
The pattern used as fill color.
SetFillColorN(Double[], PDFPattern)¶
Sets the current fill color and pattern.
Operator: scn
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
Parameters
colorSpace PDFColorSpace
The active colorspace used for fill operations
SetFlatnessTolerance(Double)¶
Set the flatness tolerance in the graphics state.
Operator: i
Parameters
flatness Double
The flatness tolerance.
SetGrayFillColor(Double)¶
Sets the current colorspace for fill operations to DeviceGray and sets the gray level.
Operator: 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
Parameters
g Double
The gray level.
SetLineCap(PDFLineCap)¶
Set the line cap style in the graphics state.
Operator: J
Parameters
lineCap PDFLineCap
The line cap style.
SetLineDashPattern(Double, Double[])¶
Sets the dash offset and pattern for stroke operations.
Operator: d
Parameters
dashPhase Double
Dash phase.
dashPattern Double[]
Dash pattern.
SetLineJoin(PDFLineJoin)¶
Set the line join style in the graphics state.
Operator: j
Parameters
lineJoin PDFLineJoin
The line join style.
SetLineWidth(Double)¶
Sets the line width in the graphics state.
Parameters
lineWidth Double
The line width
SetMiterLimit(Double)¶
Set the miter limit in the graphics state.
Operator: M
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
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
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
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
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
Parameters
pattern PDFPattern
The pattern used as stroke color.
SetStrokeColorN(Double[], PDFPattern)¶
Sets the current stroke color and pattern.
Operator: SCN
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
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
Parameters
font PDFFont
Current font.
size Double
Current font size.
SetTextHorizontalScaling(Double)¶
Sets the text horizontal scaling.
Operator: Tz
Parameters
horizontalScaling Double
Horizontal scaling specified as a percentage of normal width.
SetTextLeading(Double)¶
Sets the text leading.
Operator: TL
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
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
Parameters
textRenderingMode PDFTextRenderingMode
Text rendering mode.
SetTextRise(Double)¶
Sets the text rise.
Operator: Ts
Parameters
textRise Double
The text rise expressed in unscaled text space units.
SetWordSpacing(Double)¶
Sets the word spacing.
Operator: Tw
Parameters
wordSpacing Double
The word spacing expressed in unscaled text space units.
ShowFormXObject(PDFFormXObject)¶
Shows a form XObject on the page.
Operator: Do
Parameters
xObject PDFFormXObject
Form XObject to display.
ShowImage(PDFImage)¶
Shows an image on the page.
Operator: Do
Parameters
image PDFImage
Image to display.
ShowShading(PDFShading)¶
Shows a shading on the page.
Operator: sh
Parameters
sh PDFShading
Shading to display.
ShowText(PDFCosBinaryString)¶
Shows the specified text on the page.
Operator: Tj
Parameters
text PDFCosBinaryString
Text to show on the page.
ShowTextArray(PDFCosArray)¶
Shows one or more text strings, allowing individual glyph positioning.
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.
VCurveTo(Double, Double, Double, Double)¶
Append a cubic Bézier curve to the current path.
Operator: v
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.
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.
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.
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
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).