Class PdfCanvas
- Direct Known Subclasses:
-
PdfPatternCanvas
,Type3Glyph
-
Field Summary
Modifier and TypeFieldDescriptionprotected PdfStream
the content stream for this canvas object.protected CanvasGraphicsState
the current graphics state.protected PdfDocument
the document that the resulting content stream of this canvas will be written to.protected Stack<CanvasGraphicsState>
a LIFO stack of graphics state saved states.The list where we save/restore the layer depth.protected int
a counter variable for the marked content stack.protected PdfResources
the resources for the page that this canvas belongs to. -
Constructor Summary
ConstructorDescriptionPdfCanvas
(PdfDocument doc, int pageNum) Convenience method for fast PdfCanvas creation by a certain page.Convenience method for fast PdfCanvas creation by a certain page.Convenience method for fast PdfCanvas creation by a certain page.PdfCanvas
(PdfStream contentStream, PdfResources resources, PdfDocument document) Creates PdfCanvas from content stream of page, form XObject, pattern etc.PdfCanvas
(PdfFormXObject xObj, PdfDocument document) Creates a PdfCanvas from a PdfFormXObject. -
Method Summary
Modifier and TypeMethodDescriptionaddImageAt
(ImageData image, float x, float y, boolean asInline) CreatesPdfImageXObject
from image and adds it to the specified position.addImageFittedIntoRectangle
(ImageData image, Rectangle rect, boolean asInline) CreatesPdfImageXObject
from image and fitted into specific rectangle on canvas.addImageWithTransformationMatrix
(ImageData image, float a, float b, float c, float d, float e, float f) CreatesPdfImageXObject
from image and adds it to canvas.addImageWithTransformationMatrix
(ImageData image, float a, float b, float c, float d, float e, float f, boolean asInline) CreatesPdfImageXObject
from image and adds it to canvas.protected void
addInlineImage
(PdfImageXObject imageXObject, float a, float b, float c, float d, float e, float f) AddsPdfImageXObject
to canvas.addXObject
(PdfXObject xObject) AddsPdfXObject
on canvas.addXObjectAt
(PdfXObject xObject, float x, float y) AddsPdfXObject
to the specified position.addXObjectFittedIntoRectangle
(PdfXObject xObject, Rectangle rect) AddsPdfXObject
fitted into specific rectangle on canvas.addXObjectWithTransformationMatrix
(PdfXObject xObject, float a, float b, float c, float d, float e, float f) AddsPdfXObject
to canvas.arc
(double x1, double y1, double x2, double y2, double startAng, double extent) Draws a partial ellipse inscribed within the rectangle x1,y1,x2,y2, starting at startAng degrees and covering extent degrees.arcContinuous
(double x1, double y1, double x2, double y2, double startAng, double extent) Draws a partial ellipse with the preceding line to the start of the arc to prevent path broking.void
attachContentStream
(PdfStream contentStream) Attaches new content stream to the canvas.beginLayer
(IPdfOCG layer) Begins a graphic block whose visibility is controlled by thelayer
.Manually start a Marked Content sequence.beginMarkedContent
(PdfName tag, PdfDictionary properties) Manually start a Marked Content sequence with properties.Begins text block (PDF BT operator).Begins variable text blockstatic List
bezierArc
(double x1, double y1, double x2, double y2, double startAng, double extent) Generates an array of bezier curves to draw an arc.circle
(double x, double y, double r) Draws a circle.clip()
Modify the current clipping path by intersecting it with the current path, using the nonzero winding rule to determine which regions lie inside the clipping path.Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath.Closes the path, fills it using the even-odd rule to determine the region to fill and strokes it.Closes the path, fills it using the non-zero winding number rule to determine the region to fill and strokes it.Closes the path and strokes it.closeTag()
Manually close a tag, ending a Marked Content sequence.concatMatrix
(double a, double b, double c, double d, double e, double f) Concatenates the 2x3 affine transformation matrix to the current matrix in the content stream managed by this Canvas.concatMatrix
(AffineTransform transform) Concatenates the affine transformation matrix to the current matrix in the content stream managed by this Canvas.concatMatrix
(PdfArray array) Concatenates the 2x3 affine transformation matrix to the current matrix in the content stream managed by this Canvas.curveFromTo
(double x1, double y1, double x3, double y3) Appends a Bezier curve to the path, starting from the current point.curveTo
(double x2, double y2, double x3, double y3) Appends a Bezier curve to the path, starting from the current point.curveTo
(double x1, double y1, double x2, double y2, double x3, double y3) Appends a Bêzier curve to the path, starting from the current point.ellipse
(double x1, double y1, double x2, double y2) Draws an ellipse inscribed within the rectangle x1,y1,x2,y2.endLayer()
Ends OCG layer.Manually end a Marked Content sequence.endPath()
Ends the path without filling or stroking it.endText()
Ends text block (PDF ET operator).Ends variable text blockeoClip()
Modify the current clipping path by intersecting it with the current path, using the even-odd rule to determine which regions lie inside the clipping path.eoFill()
EOFills current path.Fills the path, using the even-odd rule to determine the region to fill and strokes it.fill()
Fills current path.Fills the path using the non-zero winding number rule to determine the region to fill and strokes it.Please, use this method with caution and only if you know what you are doing.Get the document this canvas belongs toGets currentCanvasGraphicsState
.Get the resources of the page that this canvas belongs to..lineTo
(double x, double y) Appends a straight line segment from the current point (x, y).moveText
(double x, double y) Moves text by shifting text line matrix (PDF Td operator).moveTextWithLeading
(float x, float y) Moves to the start of the next line, offset from the start of the current line.moveTo
(double x, double y) Move the current point (x, y), omitting any connecting line segment.newlineShowText
(float wordSpacing, float charSpacing, String text) Moves to the next line and shows text string, using the given values of the character and word spacing parameters.newlineShowText
(String text) Moves to the next line and showstext
.Moves to the start of the next line.Manually open a canvas tag, beginning a Marked Content sequence.openTag
(TagReference tagReference) Open a tag, beginning a Marked Content sequence.paintShading
(PdfShading shading) Paints a shading object and adds it to the resources of this canvasrectangle
(double x, double y, double width, double height) Draws a rectangle.Draws a rectangle.void
release()
Releases the canvas.Changes the current color for filling paths to black.Changes the current color for filling paths to black.Changes the current color for filling paths to black.Changes the current color for stroking paths to black.Changes the current color for stroking paths to black.Changes the current color for stroking paths to black.Restores graphics state.roundRectangle
(double x, double y, double width, double height, double radius) Draws rounded rectangle.Saves graphics state.setCharacterSpacing
(float charSpacing) Sets the character spacing parameter.Changes the current color for paths.setColor
(PdfColorSpace colorSpace, float[] colorValue, boolean fill) Changes the current color for paths.setColor
(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern, boolean fill) Changes the current color for paths with an explicitly defined pattern.setExtGState
(PdfExtGState extGState) Sets the ExtGState dictionary for the current graphics statesetExtGState
(PdfDictionary extGState) Sets the ExtGState dictionary for the current graphics statesetFillColor
(Color color) Changes the current color for filling paths.setFillColorCmyk
(float c, float m, float y, float k) Changes the current color for filling paths to a CMYK value.setFillColorGray
(float g) Changes the current color for filling paths to a grayscale value.setFillColorRgb
(float r, float g, float b) Changes the current color for filling paths to an RGB value.setFillColorShading
(PdfPattern.Shading shading) Adds or changes the shading of the current fill color path.setFlatnessTolerance
(float flatnessTolerance) Changes the Flatness.setFontAndSize
(PdfFont font, float size) Sets font and size (PDF Tf operator).setHorizontalScaling
(float scale) Sets the horizontal scaling parameter.setLeading
(float leading) Sets the text leading parameter.setLineCapStyle
(int lineCapStyle) Sets the line cap style, the shape to be used at the ends of open subpaths when they are stroked.setLineDash
(float phase) Changes the value of the line dash pattern.setLineDash
(float[] array, float phase) Changes the value of the line dash pattern.setLineDash
(float unitsOn, float phase) Changes the value of the line dash pattern.setLineDash
(float unitsOn, float unitsOff, float phase) Changes the value of the line dash pattern.setLineJoinStyle
(int lineJoinStyle) Sets the line join style, the shape to be used at the corners of paths when they are stroked.setLineWidth
(float lineWidth) Sets line width.setMiterLimit
(float miterLimit) Sets the miter limit, a parameter specifying the maximum length a miter join may extend beyond the join point, relative to the angle of the line segments.setRenderingIntent
(PdfName renderingIntent) Set the rendering intent.setStrokeColor
(Color color) Changes the current color for stroking paths.setStrokeColorCmyk
(float c, float m, float y, float k) Changes the current color for stroking paths to a CMYK value.setStrokeColorGray
(float g) Changes the current color for stroking paths to a grayscale value.setStrokeColorRgb
(float r, float g, float b) Changes the current color for stroking paths to an RGB value.setStrokeColorShading
(PdfPattern.Shading shading) Adds or changes the shading of the current stroke color path.setTextMatrix
(float x, float y) Changes the text matrix.setTextMatrix
(float a, float b, float c, float d, float x, float y) Replaces the text matrix.setTextMatrix
(AffineTransform transform) Replaces the text matrix.setTextRenderingMode
(int textRenderingMode) Sets text rendering mode.setTextRise
(float textRise) Sets the text rise parameter.setWordSpacing
(float wordSpacing) Sets the word spacing parameter.Shows text (operator Tj).showText
(GlyphLine text, Iterator<GlyphLine.GlyphLinePart> iterator) Shows text (operator Tj).Shows text (operator TJ)Shows text (operator Tj).stroke()
Strokes the path.writeLiteral
(char c) Outputs achar
directly to the content.writeLiteral
(float n) Outputs afloat
directly to the content.Outputs aString
directly to the content.
-
Field Details
-
gsStack
a LIFO stack of graphics state saved states. -
currentGs
the current graphics state. -
contentStream
the content stream for this canvas object. -
resources
the resources for the page that this canvas belongs to.- See Also:
-
document
the document that the resulting content stream of this canvas will be written to. -
mcDepth
protected int mcDeptha counter variable for the marked content stack. -
layerDepth
The list where we save/restore the layer depth.
-
-
Constructor Details
-
PdfCanvas
Creates PdfCanvas from content stream of page, form XObject, pattern etc.- Parameters:
-
contentStream
- The content stream -
resources
- The resources, a specialized dictionary that can be used by PDF instructions in the content stream -
document
- The document that the resulting content stream will be written to
-
PdfCanvas
Convenience method for fast PdfCanvas creation by a certain page.- Parameters:
-
page
- page to create canvas from.
-
PdfCanvas
Convenience method for fast PdfCanvas creation by a certain page.- Parameters:
-
page
- page to create canvas from. -
wrapOldContent
- true to wrap all old content streams into q/Q operators so that the state of old content streams would not affect the new one
-
PdfCanvas
Creates a PdfCanvas from a PdfFormXObject.- Parameters:
-
xObj
- the PdfFormXObject used to create the PdfCanvas -
document
- the document to which the resulting content stream will be written
-
PdfCanvas
Convenience method for fast PdfCanvas creation by a certain page.- Parameters:
-
doc
- The document -
pageNum
- The page number
-
-
Method Details
-
getResources
Get the resources of the page that this canvas belongs to..- Returns:
- PdfResources of the page that this canvas belongs to..
-
getDocument
Get the document this canvas belongs to- Returns:
- PdfDocument the document that this canvas belongs to
-
attachContentStream
Attaches new content stream to the canvas. This method is supposed to be used when you want to write in different PdfStream keeping context (gsStack, currentGs, ...) the same.- Parameters:
-
contentStream
- a content stream to attach.
-
getGraphicsState
Gets currentCanvasGraphicsState
.- Returns:
- container containing properties for the current state of the canvas.
-
release
public void release()Releases the canvas. Use this method after you finished working with canvas. -
saveState
Saves graphics state.- Returns:
- current canvas.
-
restoreState
Restores graphics state.- Returns:
- current canvas.
-
concatMatrix
Concatenates the 2x3 affine transformation matrix to the current matrix in the content stream managed by this Canvas. Contrast withsetTextMatrix(float, float, float, float, float, float)
- Parameters:
-
a
- operand 1,1 in the matrix. -
b
- operand 1,2 in the matrix. -
c
- operand 2,1 in the matrix. -
d
- operand 2,2 in the matrix. -
e
- operand 3,1 in the matrix. -
f
- operand 3,2 in the matrix. - Returns:
- current canvas
-
concatMatrix
Concatenates the 2x3 affine transformation matrix to the current matrix in the content stream managed by this Canvas. If an array not containing the 6 values of the matrix is passed, The current canvas is returned unchanged.- Parameters:
-
array
- affine transformation stored as a PdfArray with 6 values - Returns:
- current canvas
-
concatMatrix
Concatenates the affine transformation matrix to the current matrix in the content stream managed by this Canvas.- Parameters:
-
transform
- affine transformation matrix to be concatenated to the current matrix - Returns:
- current canvas
- See Also:
-
beginText
Begins text block (PDF BT operator).- Returns:
- current canvas.
-
endText
Ends text block (PDF ET operator).- Returns:
- current canvas.
-
beginVariableText
Begins variable text block- Returns:
- current canvas
-
endVariableText
Ends variable text block- Returns:
- current canvas
-
setFontAndSize
Sets font and size (PDF Tf operator).- Parameters:
-
font
- The font -
size
- The font size. - Returns:
- The edited canvas.
-
moveText
Moves text by shifting text line matrix (PDF Td operator).- Parameters:
-
x
- x coordinate. -
y
- y coordinate. - Returns:
- current canvas.
-
setLeading
Sets the text leading parameter.
The leading parameter is measured in text space units. It specifies the vertical distance between the baselines of adjacent lines of text.
- Parameters:
-
leading
- the new leading. - Returns:
- current canvas.
-
moveTextWithLeading
Moves to the start of the next line, offset from the start of the current line.
As a side effect, this sets the leading parameter in the text state.
- Parameters:
-
x
- offset of the new current point -
y
- y-coordinate of the new current point - Returns:
- current canvas.
-
newlineText
Moves to the start of the next line.- Returns:
- current canvas.
-
newlineShowText
Moves to the next line and showstext
.- Parameters:
-
text
- the text to write - Returns:
- current canvas.
-
newlineShowText
Moves to the next line and shows text string, using the given values of the character and word spacing parameters.- Parameters:
-
wordSpacing
- a parameter -
charSpacing
- a parameter -
text
- the text to write - Returns:
- current canvas.
-
setTextRenderingMode
Sets text rendering mode.- Parameters:
-
textRenderingMode
- text rendering mode @see PdfCanvasConstants. - Returns:
- current canvas.
-
setTextRise
Sets the text rise parameter.
This allows to write text in subscript or superscript mode.
- Parameters:
-
textRise
- a parameter - Returns:
- current canvas.
-
setWordSpacing
Sets the word spacing parameter.- Parameters:
-
wordSpacing
- a parameter - Returns:
- current canvas.
-
setCharacterSpacing
Sets the character spacing parameter.- Parameters:
-
charSpacing
- a parameter - Returns:
- current canvas.
-
setHorizontalScaling
Sets the horizontal scaling parameter.- Parameters:
-
scale
- a parameter. - Returns:
- current canvas.
-
setTextMatrix
Replaces the text matrix. Contrast withconcatMatrix(double, double, double, double, double, double)
- Parameters:
-
a
- operand 1,1 in the matrix. -
b
- operand 1,2 in the matrix. -
c
- operand 2,1 in the matrix. -
d
- operand 2,2 in the matrix. -
x
- operand 3,1 in the matrix. -
y
- operand 3,2 in the matrix. - Returns:
- current canvas.
-
setTextMatrix
Replaces the text matrix. Contrast withconcatMatrix(double, double, double, double, double, double)
- Parameters:
-
transform
- new textmatrix as transformation - Returns:
- current canvas
-
setTextMatrix
Changes the text matrix.- Parameters:
-
x
- operand 3,1 in the matrix. -
y
- operand 3,2 in the matrix. - Returns:
- current canvas.
-
showText
Shows text (operator Tj).- Parameters:
-
text
- text to show. - Returns:
- current canvas.
-
showText
Shows text (operator Tj).- Parameters:
-
text
- text to show. - Returns:
- current canvas.
-
showText
Shows text (operator Tj).- Parameters:
-
text
- text to show. -
iterator
- iterator over parts of the glyph line that should be wrapped into some marked content groups, e.g. /ActualText or /ReversedChars - Returns:
- current canvas.
-
showText
Shows text (operator TJ)- Parameters:
-
textArray
- the text array. Each element of array 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. The number is expressed in thousandths of a unit of text space. This amount is subtracted from the current horizontal or vertical coordinate, depending on the writing mode. - Returns:
- current canvas.
-
moveTo
Move the current point (x, y), omitting any connecting line segment.- Parameters:
-
x
- x coordinate. -
y
- y coordinate. - Returns:
- current canvas.
-
lineTo
Appends a straight line segment from the current point (x, y). The new current point is (x, y).- Parameters:
-
x
- x coordinate. -
y
- y coordinate. - Returns:
- current canvas.
-
curveTo
Appends a Bêzier curve to the path, starting from the current point.- Parameters:
-
x1
- x coordinate of the first control point. -
y1
- y coordinate of the first control point. -
x2
- x coordinate of the second control point. -
y2
- y coordinate of the second control point. -
x3
- x coordinate of the ending point. -
y3
- y coordinate of the ending point. - Returns:
- current canvas.
-
curveTo
Appends a Bezier curve to the path, starting from the current point.- Parameters:
-
x2
- x coordinate of the second control point. -
y2
- y coordinate of the second control point. -
x3
- x coordinate of the ending point. -
y3
- y coordinate of the ending point. - Returns:
- current canvas.
-
curveFromTo
Appends a Bezier curve to the path, starting from the current point.- Parameters:
-
x1
- x coordinate of the first control point. -
y1
- y coordinate of the first control point. -
x3
- x coordinate of the ending point. -
y3
- y coordinate of the ending point. - Returns:
- current canvas.
-
arc
Draws a partial ellipse inscribed within the rectangle x1,y1,x2,y2, starting at startAng degrees and covering extent degrees. Angles start with 0 to the right (+x) and increase counter-clockwise.- Parameters:
-
x1
- a corner of the enclosing rectangle. -
y1
- a corner of the enclosing rectangle. -
x2
- a corner of the enclosing rectangle. -
y2
- a corner of the enclosing rectangle. -
startAng
- starting angle in degrees. -
extent
- angle extent in degrees. - Returns:
- current canvas.
-
arcContinuous
public PdfCanvas arcContinuous(double x1, double y1, double x2, double y2, double startAng, double extent) Draws a partial ellipse with the preceding line to the start of the arc to prevent path broking. The target arc is inscribed within the rectangle x1,y1,x2,y2, starting at startAng degrees and covering extent degrees. Angles start with 0 to the right (+x) and increase counter-clockwise.- Parameters:
-
x1
- a corner of the enclosing rectangle -
y1
- a corner of the enclosing rectangle -
x2
- a corner of the enclosing rectangle -
y2
- a corner of the enclosing rectangle -
startAng
- starting angle in degrees -
extent
- angle extent in degrees - Returns:
- the current canvas
-
ellipse
Draws an ellipse inscribed within the rectangle x1,y1,x2,y2.- Parameters:
-
x1
- a corner of the enclosing rectangle -
y1
- a corner of the enclosing rectangle -
x2
- a corner of the enclosing rectangle -
y2
- a corner of the enclosing rectangle - Returns:
- current canvas.
-
bezierArc
public static ListbezierArc (double x1, double y1, double x2, double y2, double startAng, double extent) Generates an array of bezier curves to draw an arc.
(x1, y1) and (x2, y2) are the corners of the enclosing rectangle. Angles, measured in degrees, start with 0 to the right (the positive X axis) and increase counter-clockwise. The arc extends from startAng to startAng+extent. i.e. startAng=0 and extent=180 yields an openside-down semi-circle.
The resulting coordinates are of the form double[]{x1,y1,x2,y2,x3,y3, x4,y4} such that the curve goes from (x1, y1) to (x4, y4) with (x2, y2) and (x3, y3) as their respective Bezier control points.
Note: this code was taken from ReportLab (www.reportlab.org), an excellent PDF generator for Python (BSD license: http://www.reportlab.org/devfaq.html#1.3 ).- Parameters:
-
x1
- a corner of the enclosing rectangle. -
y1
- a corner of the enclosing rectangle. -
x2
- a corner of the enclosing rectangle. -
y2
- a corner of the enclosing rectangle. -
startAng
- starting angle in degrees. -
extent
- angle extent in degrees. - Returns:
- a list of double[] with the bezier curves.
-
rectangle
Draws a rectangle.- Parameters:
-
x
- x coordinate of the starting point. -
y
- y coordinate of the starting point. -
width
- width. -
height
- height. - Returns:
- current canvas.
-
rectangle
Draws a rectangle.- Parameters:
-
rectangle
- a rectangle to be drawn - Returns:
- current canvas.
-
roundRectangle
Draws rounded rectangle.- Parameters:
-
x
- x coordinate of the starting point. -
y
- y coordinate of the starting point. -
width
- width. -
height
- height. -
radius
- radius of the arc corner. - Returns:
- current canvas.
-
circle
Draws a circle. The endpoint will (x+r, y).- Parameters:
-
x
- x center of circle. -
y
- y center of circle. -
r
- radius of circle. - Returns:
- current canvas.
-
paintShading
Paints a shading object and adds it to the resources of this canvas- Parameters:
-
shading
- a shading object to be painted - Returns:
- current canvas.
-
closePath
Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath.- Returns:
- current canvas.
-
closePathEoFillStroke
Closes the path, fills it using the even-odd rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
closePathFillStroke
Closes the path, fills it using the non-zero winding number rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
endPath
Ends the path without filling or stroking it.- Returns:
- current canvas.
-
stroke
Strokes the path.- Returns:
- current canvas.
-
clip
Modify the current clipping path by intersecting it with the current path, using the nonzero winding rule to determine which regions lie inside the clipping path.- Returns:
- current canvas.
-
eoClip
Modify the current clipping path by intersecting it with the current path, using the even-odd rule to determine which regions lie inside the clipping path.- Returns:
- current canvas.
-
closePathStroke
Closes the path and strokes it.- Returns:
- current canvas.
-
fill
Fills current path.- Returns:
- current canvas.
-
fillStroke
Fills the path using the non-zero winding number rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
eoFill
EOFills current path.- Returns:
- current canvas.
-
eoFillStroke
Fills the path, using the even-odd rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
setLineWidth
Sets line width.- Parameters:
-
lineWidth
- line width. - Returns:
- current canvas.
-
setLineCapStyle
Sets the line cap style, the shape to be used at the ends of open subpaths when they are stroked.- Parameters:
-
lineCapStyle
- a line cap style to be set - Returns:
- current canvas.
- See Also:
-
setLineJoinStyle
Sets the line join style, the shape to be used at the corners of paths when they are stroked.- Parameters:
-
lineJoinStyle
- a line join style to be set - Returns:
- current canvas.
- See Also:
-
setMiterLimit
Sets the miter limit, a parameter specifying the maximum length a miter join may extend beyond the join point, relative to the angle of the line segments.- Parameters:
-
miterLimit
- a miter limit to be set - Returns:
- current canvas.
-
setLineDash
Changes the value of the line dash pattern.
The line dash pattern controls the pattern of dashes and gaps used to stroke paths. It is specified by an array and a phase. The array specifies the length of the alternating dashes and gaps. The phase specifies the distance into the dash pattern to start the dash.- Parameters:
-
phase
- the value of the phase - Returns:
- current canvas.
-
setLineDash
Changes the value of the line dash pattern.
The line dash pattern controls the pattern of dashes and gaps used to stroke paths. It is specified by an array and a phase. The array specifies the length of the alternating dashes and gaps. The phase specifies the distance into the dash pattern to start the dash.- Parameters:
-
phase
- the value of the phase -
unitsOn
- the number of units that must be 'on' (equals the number of units that must be 'off'). - Returns:
- current canvas.
-
setLineDash
Changes the value of the line dash pattern.
The line dash pattern controls the pattern of dashes and gaps used to stroke paths. It is specified by an array and a phase. The array specifies the length of the alternating dashes and gaps. The phase specifies the distance into the dash pattern to start the dash.- Parameters:
-
phase
- the value of the phase -
unitsOn
- the number of units that must be 'on' -
unitsOff
- the number of units that must be 'off' - Returns:
- current canvas.
-
setLineDash
Changes the value of the line dash pattern.
The line dash pattern controls the pattern of dashes and gaps used to stroke paths. It is specified by an array and a phase. The array specifies the length of the alternating dashes and gaps. The phase specifies the distance into the dash pattern to start the dash.- Parameters:
-
array
- length of the alternating dashes and gaps -
phase
- the value of the phase - Returns:
- current canvas.
-
setRenderingIntent
Set the rendering intent. possible values are: PdfName.AbsoluteColorimetric, PdfName.RelativeColorimetric, PdfName.Saturation, PdfName.Perceptual.- Parameters:
-
renderingIntent
- a PdfName containing a color metric - Returns:
- current canvas.
-
setFlatnessTolerance
Changes the Flatness.Flatness sets the maximum permitted distance in device pixels between the mathematically correct path and an approximation constructed from straight line segments.
- Parameters:
-
flatnessTolerance
- a value - Returns:
- current canvas.
-
setFillColor
Changes the current color for filling paths.- Parameters:
-
color
- fill color. - Returns:
- current canvas.
-
setStrokeColor
Changes the current color for stroking paths.- Parameters:
-
color
- stroke color. - Returns:
- current canvas.
-
setColor
Changes the current color for paths.- Parameters:
-
color
- the new color. -
fill
- set fill color (true
) or stroke color (false
) - Returns:
- current canvas.
-
setColor
Changes the current color for paths.- Parameters:
-
colorSpace
- the color space of the new color -
colorValue
- a list of numerical values with a length corresponding to the specs of the color space. Values should be in the range [0,1] -
fill
- set fill color (true
) or stroke color (false
) - Returns:
- current canvas.
-
setColor
public PdfCanvas setColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern, boolean fill) Changes the current color for paths with an explicitly defined pattern.- Parameters:
-
colorSpace
- the color space of the new color -
colorValue
- a list of numerical values with a length corresponding to the specs of the color space. Values should be in the range [0,1] -
pattern
- a pattern for the colored line or area -
fill
- set fill color (true
) or stroke color (false
) - Returns:
- current canvas.
-
setFillColorGray
Changes the current color for filling paths to a grayscale value.- Parameters:
-
g
- a grayscale value in the range [0,1] - Returns:
- current canvas.
-
setStrokeColorGray
Changes the current color for stroking paths to a grayscale value.- Parameters:
-
g
- a grayscale value in the range [0,1] - Returns:
- current canvas.
-
resetFillColorGray
Changes the current color for filling paths to black.- Returns:
- current canvas.
-
resetStrokeColorGray
Changes the current color for stroking paths to black.- Returns:
- current canvas.
-
setFillColorRgb
Changes the current color for filling paths to an RGB value.- Parameters:
-
r
- a red value in the range [0,1] -
g
- a green value in the range [0,1] -
b
- a blue value in the range [0,1] - Returns:
- current canvas.
-
setStrokeColorRgb
Changes the current color for stroking paths to an RGB value.- Parameters:
-
r
- a red value in the range [0,1] -
g
- a green value in the range [0,1] -
b
- a blue value in the range [0,1] - Returns:
- current canvas.
-
setFillColorShading
Adds or changes the shading of the current fill color path.- Parameters:
-
shading
- the shading - Returns:
- current canvas.
-
setStrokeColorShading
Adds or changes the shading of the current stroke color path.- Parameters:
-
shading
- the shading - Returns:
- current canvas.
-
resetFillColorRgb
Changes the current color for filling paths to black.- Returns:
- current canvas.
-
resetStrokeColorRgb
Changes the current color for stroking paths to black.- Returns:
- current canvas.
-
setFillColorCmyk
Changes the current color for filling paths to a CMYK value.- Parameters:
-
c
- a cyan value in the range [0,1] -
m
- a magenta value in the range [0,1] -
y
- a yellow value in the range [0,1] -
k
- a key (black) value in the range [0,1] - Returns:
- current canvas.
-
setStrokeColorCmyk
Changes the current color for stroking paths to a CMYK value.- Parameters:
-
c
- a cyan value in the range [0,1] -
m
- a magenta value in the range [0,1] -
y
- a yellow value in the range [0,1] -
k
- a key (black) value in the range [0,1] - Returns:
- current canvas.
-
resetFillColorCmyk
Changes the current color for filling paths to black.- Returns:
- current canvas.
-
resetStrokeColorCmyk
Changes the current color for stroking paths to black.- Returns:
- current canvas.
-
beginLayer
Begins a graphic block whose visibility is controlled by thelayer
. Blocks can be nested. Each block must be terminated by anendLayer()
.Note that nested layers with
PdfLayer.addChild(PdfLayer)
only require a single call to this method and a single call toendLayer()
; all the nesting control is built in.- Parameters:
-
layer
- The layer to begin - Returns:
- The edited canvas.
-
endLayer
Ends OCG layer.- Returns:
- current canvas.
-
addImageWithTransformationMatrix
public PdfXObject addImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f) CreatesPdfImageXObject
from image and adds it to canvas.The float arguments will be used in concatenating the transformation matrix as operands.
- Parameters:
-
image
- the image from whichPdfImageXObject
will be created -
a
- an element of the transformation matrix -
b
- an element of the transformation matrix -
c
- an element of the transformation matrix -
d
- an element of the transformation matrix -
e
- an element of the transformation matrix -
f
- an element of the transformation matrix - Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
- See Also:
-
addImageWithTransformationMatrix
public PdfXObject addImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f, boolean asInline) CreatesPdfImageXObject
from image and adds it to canvas.The float arguments will be used in concatenating the transformation matrix as operands.
- Parameters:
-
image
- the image from whichPdfImageXObject
will be created -
a
- an element of the transformation matrix -
b
- an element of the transformation matrix -
c
- an element of the transformation matrix -
d
- an element of the transformation matrix -
e
- an element of the transformation matrix -
f
- an element of the transformation matrix -
asInline
- true if to add image as in-line - Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
- See Also:
-
addImageFittedIntoRectangle
CreatesPdfImageXObject
from image and fitted into specific rectangle on canvas. The created imageXObject will be fit inside on the specified rectangle without preserving aspect ratio.The x, y, width and height parameters of the rectangle will be used in concatenating the transformation matrix as operands.
- Parameters:
-
image
- the image from whichPdfImageXObject
will be created -
rect
- the rectangle in which the created imageXObject will be fit -
asInline
- true if to add image as in-line - Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
- See Also:
-
addImageAt
CreatesPdfImageXObject
from image and adds it to the specified position.- Parameters:
-
image
- the image from whichPdfImageXObject
will be created -
x
- the horizontal position of the imageXObject -
y
- the vertical position of the imageXObject -
asInline
- true if to add image as in-line - Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
-
addXObjectWithTransformationMatrix
public PdfCanvas addXObjectWithTransformationMatrix(PdfXObject xObject, float a, float b, float c, float d, float e, float f) AddsPdfXObject
to canvas.The float arguments will be used in concatenating the transformation matrix as operands.
- Parameters:
-
xObject
- the xObject to add -
a
- an element of the transformation matrix -
b
- an element of the transformation matrix -
c
- an element of the transformation matrix -
d
- an element of the transformation matrix -
e
- an element of the transformation matrix -
f
- an element of the transformation matrix - Returns:
- the current canvas
- See Also:
-
addXObjectAt
AddsPdfXObject
to the specified position.- Parameters:
-
xObject
- the xObject to add -
x
- the horizontal position of the xObject -
y
- the vertical position of the xObject - Returns:
- the current canvas
-
addXObjectFittedIntoRectangle
AddsPdfXObject
fitted into specific rectangle on canvas.- Parameters:
-
xObject
- the xObject to add -
rect
- the rectangle in which the xObject will be fitted - Returns:
- the current canvas
- See Also:
-
addXObject
AddsPdfXObject
on canvas.Note: the
PdfImageXObject
will be placed at coordinates (0, 0) with its original width and height, thePdfFormXObject
will be fitted in its bBox.- Parameters:
-
xObject
- the xObject to add - Returns:
- the current canvas
-
setExtGState
Sets the ExtGState dictionary for the current graphics state- Parameters:
-
extGState
- a dictionary that maps resource names to graphics state parameter dictionaries - Returns:
- current canvas.
-
setExtGState
Sets the ExtGState dictionary for the current graphics state- Parameters:
-
extGState
- a dictionary that maps resource names to graphics state parameter dictionaries - Returns:
- current canvas.
-
beginMarkedContent
Manually start a Marked Content sequence. Used primarily for Tagged PDF- Parameters:
-
tag
- the type of content contained - Returns:
- current canvas
-
beginMarkedContent
Manually start a Marked Content sequence with properties. Used primarily for Tagged PDF- Parameters:
-
tag
- the type of content that will be contained -
properties
- the properties of the content, including Marked Content ID. If null, the PDF marker is BMC, else it is BDC - Returns:
- current canvas
-
endMarkedContent
Manually end a Marked Content sequence. Used primarily for Tagged PDF- Returns:
- current canvas
-
openTag
Manually open a canvas tag, beginning a Marked Content sequence. Used primarily for Tagged PDF- Parameters:
-
tag
- the type of content that will be contained - Returns:
- current canvas
-
openTag
Open a tag, beginning a Marked Content sequence. This MC sequence will belong to the tag from the document logical structure.
CanvasTag will be automatically created with assigned mcid(Marked Content id) to it. Mcid serves as a reference between Marked Content sequence and logical structure element.- Parameters:
-
tagReference
- reference to the tag from the document logical structure - Returns:
- current canvas
-
closeTag
Manually close a tag, ending a Marked Content sequence. Used primarily for Tagged PDF- Returns:
- current canvas
-
writeLiteral
Outputs aString
directly to the content.- Parameters:
-
s
- theString
- Returns:
- current canvas.
-
writeLiteral
Outputs achar
directly to the content.- Parameters:
-
c
- thechar
- Returns:
- current canvas.
-
writeLiteral
Outputs afloat
directly to the content.- Parameters:
-
n
- thefloat
- Returns:
- current canvas.
-
getContentStream
Please, use this method with caution and only if you know what you are doing. Manipulating with underlying stream object of canvas could lead to corruption of it's data.- Returns:
- the content stream to which this canvas object writes.
-
addInlineImage
protected void addInlineImage(PdfImageXObject imageXObject, float a, float b, float c, float d, float e, float f) AddsPdfImageXObject
to canvas.- Parameters:
-
imageXObject
- thePdfImageXObject
object -
a
- an element of the transformation matrix -
b
- an element of the transformation matrix -
c
- an element of the transformation matrix -
d
- an element of the transformation matrix -
e
- an element of the transformation matrix -
f
- an element of the transformation matrix
-