Class PdfCanvas
- java.lang.Object
-
- com.itextpdf.kernel.pdf.canvas.PdfCanvas
-
- Direct Known Subclasses:
PdfPatternCanvas,Type3Glyph
public class PdfCanvas extends java.lang.ObjectPdfCanvas class represents an algorithm for writing data into content stream. To write into page content, create PdfCanvas from a page instance. To write into form XObject, create PdfCanvas from a form XObject instance. Make sure to call PdfCanvas.release() after you finished writing to the canvas. It will save some memory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPdfCanvas.CheckColorMode
-
Field Summary
Fields Modifier and Type Field Description private static byte[]bprivate static byte[]Bprivate static byte[]BDCprivate static byte[]BIprivate static byte[]BMCprivate static byte[]bStarprivate static byte[]BStarprivate static byte[]BTprivate static byte[]cprivate static byte[]cmprivate static PdfDeviceCs.Cmykcmykprotected PdfStreamcontentStreamthe content stream for this canvas object.private static byte[]csprivate static byte[]CSprotected CanvasGraphicsStatecurrentGsthe current graphics state.private static byte[]dprivate booleandefaultDeviceGrayBlackColorCheckRequiredprivate static byte[]Doprotected PdfDocumentdocumentthe document that the resulting content stream of this canvas will be written to.protected booleandrawingOnPageprivate static byte[]EIprivate static byte[]EMCprivate static byte[]ETprivate static byte[]fprivate static byte[]fStarprivate static byte[]gprivate static byte[]Gprivate static PdfDeviceCs.Graygrayprivate static byte[]gsprotected java.util.Stack<CanvasGraphicsState>gsStacka LIFO stack of graphics state saved states.private static byte[]hprivate static byte[]iprivate static byte[]IDprivate static floatIDENTITY_MATRIX_EPSprivate static byte[]jprivate static byte[]Jprivate static byte[]kprivate static byte[]Kprivate static byte[]lprotected java.util.List<java.lang.Integer>layerDepthThe list where we save/restore the layer depth.private static byte[]mprivate static byte[]Mprotected intmcDeptha counter variable for the marked content stack.private static byte[]nprivate static PdfSpecialCs.Patternpatternprivate static byte[]qprivate static byte[]Qprivate static byte[]reprotected PdfResourcesresourcesthe resources for the page that this canvas belongs to.private static byte[]rgprivate static byte[]RGprivate static PdfDeviceCs.Rgbrgbprivate static byte[]riprivate static byte[]sprivate static byte[]Sprivate static byte[]scnprivate static byte[]SCNprivate static byte[]shprivate java.util.Stack<Tuple2<PdfName,PdfDictionary>>tagStructureStackprivate static byte[]Tcprivate static byte[]Tdprivate static byte[]TDprivate static byte[]Tfprivate static byte[]Tjprivate static byte[]TJprivate static byte[]TLprivate static byte[]Tmprivate static byte[]Trprivate static byte[]Tsprivate static byte[]TStarprivate static byte[]Twprivate static byte[]Tzprivate static byte[]vprivate static byte[]wprivate static byte[]Wprivate static byte[]WStarprivate static byte[]y
-
Constructor Summary
Constructors Constructor Description PdfCanvas(PdfDocument doc, int pageNum)Convenience method for fast PdfCanvas creation by a certain page.PdfCanvas(PdfPage page)Convenience method for fast PdfCanvas creation by a certain page.PdfCanvas(PdfPage page, boolean wrapOldContent)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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private PdfCanvasaddFormAt(PdfFormXObject form, float x, float y)AddsPdfFormXObjectto the specified position.private PdfCanvasaddFormFittedIntoRectangle(PdfFormXObject form, Rectangle rect)AddsPdfFormXObjectfitted into specific rectangle on canvas.private PdfCanvasaddFormWithTransformationMatrix(PdfFormXObject form, float a, float b, float c, float d, float e, float f, boolean writeIdentityMatrix)AddsPdfFormXObjectto canvas.PdfXObjectaddImageAt(ImageData image, float x, float y, boolean asInline)CreatesPdfImageXObjectfrom image and adds it to the specified position.private PdfCanvasaddImageAt(PdfImageXObject image, float x, float y)AddsPdfImageXObjectto the specified position.PdfXObjectaddImageFittedIntoRectangle(ImageData image, Rectangle rect, boolean asInline)CreatesPdfImageXObjectfrom image and fitted into specific rectangle on canvas.private PdfCanvasaddImageFittedIntoRectangle(PdfImageXObject image, Rectangle rect)AddsPdfImageXObjectfitted into specific rectangle on canvas.PdfXObjectaddImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f)CreatesPdfImageXObjectfrom image and adds it to canvas.PdfXObjectaddImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f, boolean asInline)CreatesPdfImageXObjectfrom image and adds it to canvas.private PdfCanvasaddImageWithTransformationMatrix(PdfXObject xObject, float a, float b, float c, float d, float e, float f)AddsPdfXObjectto canvas.protected voidaddInlineImage(PdfImageXObject imageXObject, float a, float b, float c, float d, float e, float f)AddsPdfImageXObjectto canvas.private voidaddToPropertiesAndBeginLayer(IPdfOCG layer)PdfCanvasaddXObject(PdfXObject xObject)AddsPdfXObjecton canvas.PdfCanvasaddXObjectAt(PdfXObject xObject, float x, float y)AddsPdfXObjectto the specified position.PdfCanvasaddXObjectFittedIntoRectangle(PdfXObject xObject, Rectangle rect)AddsPdfXObjectfitted into specific rectangle on canvas.PdfCanvasaddXObjectWithTransformationMatrix(PdfXObject xObject, float a, float b, float c, float d, float e, float f)AddsPdfXObjectto canvas.private voidapplyRotation(PdfPage page)PdfCanvasarc(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.PdfCanvasarcContinuous(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.voidattachContentStream(PdfStream contentStream)Attaches new content stream to the canvas.PdfCanvasbeginLayer(IPdfOCG layer)Begins a graphic block whose visibility is controlled by thelayer.private intbeginLayerTree(PdfLayer layer, java.util.Set<PdfLayer> layers)This method is used to traverse parent tree and begin all layers in it.PdfCanvasbeginMarkedContent(PdfName tag)Manually start a Marked Content sequence.PdfCanvasbeginMarkedContent(PdfName tag, PdfDictionary properties)Manually start a Marked Content sequence with properties.PdfCanvasbeginText()Begins text block (PDF BT operator).PdfCanvasbeginVariableText()Begins variable text blockstatic java.util.List<double[]>bezierArc(double x1, double y1, double x2, double y2, double startAng, double extent)Generates an array of bezier curves to draw an arc.private static float[]calculateTransformationMatrix(Vector expectedMin, Vector expectedMax, Vector actualMin, Vector actualMax)private voidcheckDefaultDeviceGrayBlackColor(PdfCanvas.CheckColorMode checkColorMode)private voidcheckIsoConformanceWritingOnContent()private voidcheckTextOnAddition(GlyphLine text)private voidcheckTextOnAddition(java.lang.String text)PdfCanvascircle(double x, double y, double r)Draws a circle.PdfCanvasclip()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.PdfCanvasclosePath()Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath.PdfCanvasclosePathEoFillStroke()Closes the path, fills it using the even-odd rule to determine the region to fill and strokes it.PdfCanvasclosePathFillStroke()Closes the path, fills it using the non-zero winding number rule to determine the region to fill and strokes it.PdfCanvasclosePathStroke()Closes the path and strokes it.PdfCanvascloseTag()Manually close a tag, ending a Marked Content sequence.PdfCanvasconcatMatrix(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.PdfCanvasconcatMatrix(AffineTransform transform)Concatenates the affine transformation matrix to the current matrix in the content stream managed by this Canvas.PdfCanvasconcatMatrix(PdfArray array)Concatenates the 2x3 affine transformation matrix to the current matrix in the content stream managed by this Canvas.private ColorcreateColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern)PdfCanvascurveFromTo(double x1, double y1, double x3, double y3)Appends a Bezier curve to the path, starting from the current point.PdfCanvascurveTo(double x2, double y2, double x3, double y3)Appends a Bezier curve to the path, starting from the current point.PdfCanvascurveTo(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.private PdfCanvasdrawArc(double x1, double y1, double x2, double y2, double startAng, double extent, boolean continuous)PdfCanvasellipse(double x1, double y1, double x2, double y2)Draws an ellipse inscribed within the rectangle x1,y1,x2,y2.PdfCanvasendLayer()Ends OCG layer.PdfCanvasendMarkedContent()Manually end a Marked Content sequence.PdfCanvasendPath()Ends the path without filling or stroking it.PdfCanvasendText()Ends text block (PDF ET operator).PdfCanvasendVariableText()Ends variable text blockprivate PdfStreamensureStreamDataIsReadyToBeProcessed(PdfStream stream)PdfCanvaseoClip()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.PdfCanvaseoFill()EOFills current path.PdfCanvaseoFillStroke()Fills the path, using the even-odd rule to determine the region to fill and strokes it.PdfCanvasfill()Fills current path.PdfCanvasfillStroke()Fills the path using the non-zero winding number rule to determine the region to fill and strokes it.private PdfCanvas.CheckColorModegetColorKeyForText()PdfStreamgetContentStream()Please, use this method with caution and only if you know what you are doing.private PdfArraygetDashPatternArray(float phase)private PdfArraygetDashPatternArray(float[] dashArray, float phase)PdfDocumentgetDocument()Get the document this canvas belongs toprivate static double[]getEllipseRoundedRectPoints(double x, double y, double width, double height, double rx, double ry)CanvasGraphicsStategetGraphicsState()Gets currentCanvasGraphicsState.private static PdfStreamgetPageStream(PdfPage page)PdfResourcesgetResources()Get the resources of the page that this canvas belongs to..private floatgetSubrangeWidth(GlyphLine text, int from, int to)Finds horizontal distance between the start of the `from` glyph and end of `to` glyph.private floatgetSubrangeYDelta(GlyphLine text, int from, int to)private floatgetWordSpacingAddition(Glyph glyph)private static booleanisIdentityMatrix(float a, float b, float c, float d, float e, float f)private static <T> java.util.List<T>iteratorToList(java.util.Iterator<T> iterator)PdfCanvaslineTo(double x, double y)Appends a straight line segment from the current point (x, y).PdfCanvasmoveText(double x, double y)Moves text by shifting text line matrix (PDF Td operator).PdfCanvasmoveTextWithLeading(float x, float y)Moves to the start of the next line, offset from the start of the current line.PdfCanvasmoveTo(double x, double y)Move the current point (x, y), omitting any connecting line segment.PdfCanvasnewlineShowText(float wordSpacing, float charSpacing, java.lang.String text)Moves to the next line and shows text string, using the given values of the character and word spacing parameters.PdfCanvasnewlineShowText(java.lang.String text)Moves to the next line and showstext.PdfCanvasnewlineText()Moves to the start of the next line.PdfCanvasopenTag(CanvasTag tag)Manually open a canvas tag, beginning a Marked Content sequence.PdfCanvasopenTag(TagReference tagReference)Open a tag, beginning a Marked Content sequence.PdfCanvaspaintShading(AbstractPdfShading shading)Paints a shading object and adds it to the resources of this canvasPdfCanvasrectangle(double x, double y, double width, double height)Draws a rectangle.PdfCanvasrectangle(Rectangle rectangle)Draws a rectangle.voidrelease()Releases the canvas.PdfCanvasresetFillColorCmyk()Changes the current color for filling paths to black.PdfCanvasresetFillColorGray()Changes the current color for filling paths to black.PdfCanvasresetFillColorRgb()Changes the current color for filling paths to black.PdfCanvasresetStrokeColorCmyk()Changes the current color for stroking paths to black.PdfCanvasresetStrokeColorGray()Changes the current color for stroking paths to black.PdfCanvasresetStrokeColorRgb()Changes the current color for stroking paths to black.PdfCanvasrestoreState()Restores graphics state.PdfCanvasroundRectangle(double x, double y, double width, double height, double radius)Draws rounded rectangle.PdfCanvasroundRectangle(double x, double y, double width, double height, double rx, double ry, AffineTransform transform)Draws rounded rectangle.private voidsaveColorSpaceToPageResourcesIfNeeded(PdfStream image)PdfCanvassaveState()Saves graphics state.PdfCanvassetCharacterSpacing(float charSpacing)Sets the character spacing parameter.PdfCanvassetColor(Color color, boolean fill)Changes the current color for paths.PdfCanvassetColor(PdfColorSpace colorSpace, float[] colorValue, boolean fill)Changes the current color for paths.PdfCanvassetColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern, boolean fill)Changes the current color for paths with an explicitly defined pattern.voidsetDrawingOnPage(boolean drawingOnPage)Sets whether we are currently drawing on a page.PdfCanvassetExtGState(PdfExtGState extGState)Sets the ExtGState dictionary for the current graphics statePdfExtGStatesetExtGState(PdfDictionary extGState)Sets the ExtGState dictionary for the current graphics statePdfCanvassetFillColor(Color color)Changes the current color for filling paths.PdfCanvassetFillColorCmyk(float c, float m, float y, float k)Changes the current color for filling paths to a CMYK value.PdfCanvassetFillColorGray(float g)Changes the current color for filling paths to a grayscale value.PdfCanvassetFillColorRgb(float r, float g, float b)Changes the current color for filling paths to an RGB value.PdfCanvassetFillColorShading(PdfPattern.Shading shading)Adds or changes the shading of the current fill color path.PdfCanvassetFlatnessTolerance(float flatnessTolerance)Changes the Flatness.PdfCanvassetFontAndSize(PdfFont font, float size)Sets font and size (PDF Tf operator).PdfCanvassetHorizontalScaling(float scale)Sets the horizontal scaling parameter.PdfCanvassetLeading(float leading)Sets the text leading parameter.PdfCanvassetLineCapStyle(int lineCapStyle)Sets the line cap style, the shape to be used at the ends of open subpaths when they are stroked.PdfCanvassetLineDash(float phase)Changes the value of the line dash pattern.PdfCanvassetLineDash(float[] array, float phase)Changes the value of the line dash pattern.PdfCanvassetLineDash(float unitsOn, float phase)Changes the value of the line dash pattern.PdfCanvassetLineDash(float unitsOn, float unitsOff, float phase)Changes the value of the line dash pattern.PdfCanvassetLineJoinStyle(int lineJoinStyle)Sets the line join style, the shape to be used at the corners of paths when they are stroked.PdfCanvassetLineWidth(float lineWidth)Sets line width.PdfCanvassetMiterLimit(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.PdfCanvassetRenderingIntent(PdfName renderingIntent)Set the rendering intent.PdfCanvassetStrokeColor(Color color)Changes the current color for stroking paths.PdfCanvassetStrokeColorCmyk(float c, float m, float y, float k)Changes the current color for stroking paths to a CMYK value.PdfCanvassetStrokeColorGray(float g)Changes the current color for stroking paths to a grayscale value.PdfCanvassetStrokeColorRgb(float r, float g, float b)Changes the current color for stroking paths to an RGB value.PdfCanvassetStrokeColorShading(PdfPattern.Shading shading)Adds or changes the shading of the current stroke color path.PdfCanvassetTextMatrix(float x, float y)Changes the text matrix.PdfCanvassetTextMatrix(float a, float b, float c, float d, float x, float y)Replaces the text matrix.PdfCanvassetTextMatrix(AffineTransform transform)Replaces the text matrix.PdfCanvassetTextRenderingMode(int textRenderingMode)Sets text rendering mode.PdfCanvassetTextRise(float textRise)Sets the text rise parameter.PdfCanvassetWordSpacing(float wordSpacing)Sets the word spacing parameter.PdfCanvasshowText(GlyphLine text)Shows text (operator Tj).PdfCanvasshowText(GlyphLine text, java.util.Iterator<GlyphLine.GlyphLinePart> iterator)Shows text (operator Tj).PdfCanvasshowText(PdfArray textArray)Shows text (operator TJ)PdfCanvasshowText(java.lang.String text)Shows text (operator Tj).private voidshowTextInt(java.lang.String text)A helper to insert into the content stream thetextconverted to bytes according to the font's encoding.PdfCanvasstroke()Strokes the path.PdfCanvaswriteLiteral(char c)Outputs achardirectly to the content.PdfCanvaswriteLiteral(float n)Outputs afloatdirectly to the content.PdfCanvaswriteLiteral(java.lang.String s)Outputs aStringdirectly to the content.
-
-
-
Field Detail
-
B
private static final byte[] B
-
b
private static final byte[] b
-
BDC
private static final byte[] BDC
-
BI
private static final byte[] BI
-
BMC
private static final byte[] BMC
-
BStar
private static final byte[] BStar
-
bStar
private static final byte[] bStar
-
BT
private static final byte[] BT
-
c
private static final byte[] c
-
cm
private static final byte[] cm
-
cs
private static final byte[] cs
-
CS
private static final byte[] CS
-
d
private static final byte[] d
-
Do
private static final byte[] Do
-
EI
private static final byte[] EI
-
EMC
private static final byte[] EMC
-
ET
private static final byte[] ET
-
f
private static final byte[] f
-
fStar
private static final byte[] fStar
-
G
private static final byte[] G
-
g
private static final byte[] g
-
gs
private static final byte[] gs
-
h
private static final byte[] h
-
i
private static final byte[] i
-
ID
private static final byte[] ID
-
j
private static final byte[] j
-
J
private static final byte[] J
-
K
private static final byte[] K
-
k
private static final byte[] k
-
l
private static final byte[] l
-
m
private static final byte[] m
-
M
private static final byte[] M
-
n
private static final byte[] n
-
q
private static final byte[] q
-
Q
private static final byte[] Q
-
re
private static final byte[] re
-
rg
private static final byte[] rg
-
RG
private static final byte[] RG
-
ri
private static final byte[] ri
-
S
private static final byte[] S
-
s
private static final byte[] s
-
scn
private static final byte[] scn
-
SCN
private static final byte[] SCN
-
sh
private static final byte[] sh
-
Tc
private static final byte[] Tc
-
Td
private static final byte[] Td
-
TD
private static final byte[] TD
-
Tf
private static final byte[] Tf
-
TJ
private static final byte[] TJ
-
Tj
private static final byte[] Tj
-
TL
private static final byte[] TL
-
Tm
private static final byte[] Tm
-
Tr
private static final byte[] Tr
-
Ts
private static final byte[] Ts
-
TStar
private static final byte[] TStar
-
Tw
private static final byte[] Tw
-
Tz
private static final byte[] Tz
-
v
private static final byte[] v
-
W
private static final byte[] W
-
w
private static final byte[] w
-
WStar
private static final byte[] WStar
-
y
private static final byte[] y
-
gray
private static final PdfDeviceCs.Gray gray
-
rgb
private static final PdfDeviceCs.Rgb rgb
-
cmyk
private static final PdfDeviceCs.Cmyk cmyk
-
pattern
private static final PdfSpecialCs.Pattern pattern
-
IDENTITY_MATRIX_EPS
private static final float IDENTITY_MATRIX_EPS
- See Also:
- Constant Field Values
-
defaultDeviceGrayBlackColorCheckRequired
private boolean defaultDeviceGrayBlackColorCheckRequired
-
gsStack
protected java.util.Stack<CanvasGraphicsState> gsStack
a LIFO stack of graphics state saved states.
-
currentGs
protected CanvasGraphicsState currentGs
the current graphics state.
-
contentStream
protected PdfStream contentStream
the content stream for this canvas object.
-
resources
protected PdfResources resources
the resources for the page that this canvas belongs to.- See Also:
PdfResources
-
document
protected PdfDocument document
the document that the resulting content stream of this canvas will be written to.
-
mcDepth
protected int mcDepth
a counter variable for the marked content stack.
-
layerDepth
protected java.util.List<java.lang.Integer> layerDepth
The list where we save/restore the layer depth.
-
tagStructureStack
private java.util.Stack<Tuple2<PdfName,PdfDictionary>> tagStructureStack
-
drawingOnPage
protected boolean drawingOnPage
-
-
Constructor Detail
-
PdfCanvas
public PdfCanvas(PdfStream contentStream, PdfResources resources, PdfDocument document)
Creates PdfCanvas from content stream of page, form XObject, pattern etc.- Parameters:
contentStream- The content streamresources- The resources, a specialized dictionary that can be used by PDF instructions in the content streamdocument- The document that the resulting content stream will be written to
-
PdfCanvas
public PdfCanvas(PdfPage page)
Convenience method for fast PdfCanvas creation by a certain page.- Parameters:
page- page to create canvas from.
-
PdfCanvas
public PdfCanvas(PdfPage page, boolean wrapOldContent)
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
public PdfCanvas(PdfFormXObject xObj, PdfDocument document)
Creates a PdfCanvas from a PdfFormXObject.- Parameters:
xObj- the PdfFormXObject used to create the PdfCanvasdocument- the document to which the resulting content stream will be written
-
PdfCanvas
public PdfCanvas(PdfDocument doc, int pageNum)
Convenience method for fast PdfCanvas creation by a certain page.- Parameters:
doc- The documentpageNum- The page number
-
-
Method Detail
-
getResources
public PdfResources getResources()
Get the resources of the page that this canvas belongs to..- Returns:
- PdfResources of the page that this canvas belongs to..
-
getDocument
public PdfDocument getDocument()
Get the document this canvas belongs to- Returns:
- PdfDocument the document that this canvas belongs to
-
attachContentStream
public void attachContentStream(PdfStream contentStream)
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
public CanvasGraphicsState 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
public PdfCanvas saveState()
Saves graphics state.- Returns:
- current canvas.
-
restoreState
public PdfCanvas restoreState()
Restores graphics state.- Returns:
- current canvas.
-
concatMatrix
public PdfCanvas 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. 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
public PdfCanvas concatMatrix(PdfArray array)
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
public PdfCanvas concatMatrix(AffineTransform transform)
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:
concatMatrix(double, double, double, double, double, double)
-
beginText
public PdfCanvas beginText()
Begins text block (PDF BT operator).- Returns:
- current canvas.
-
endText
public PdfCanvas endText()
Ends text block (PDF ET operator).- Returns:
- current canvas.
-
beginVariableText
public PdfCanvas beginVariableText()
Begins variable text block- Returns:
- current canvas
-
endVariableText
public PdfCanvas endVariableText()
Ends variable text block- Returns:
- current canvas
-
setFontAndSize
public PdfCanvas setFontAndSize(PdfFont font, float size)
Sets font and size (PDF Tf operator).- Parameters:
font- The fontsize- The font size.- Returns:
- The edited canvas.
-
moveText
public PdfCanvas moveText(double x, double y)
Moves text by shifting text line matrix (PDF Td operator).- Parameters:
x- x coordinate.y- y coordinate.- Returns:
- current canvas.
-
setLeading
public PdfCanvas setLeading(float leading)
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
public PdfCanvas moveTextWithLeading(float x, float y)
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 pointy- y-coordinate of the new current point- Returns:
- current canvas.
-
newlineText
public PdfCanvas newlineText()
Moves to the start of the next line.- Returns:
- current canvas.
-
newlineShowText
public PdfCanvas newlineShowText(java.lang.String text)
Moves to the next line and showstext.- Parameters:
text- the text to write- Returns:
- current canvas.
-
newlineShowText
public PdfCanvas newlineShowText(float wordSpacing, float charSpacing, java.lang.String text)
Moves to the next line and shows text string, using the given values of the character and word spacing parameters.- Parameters:
wordSpacing- a parametercharSpacing- a parametertext- the text to write- Returns:
- current canvas.
-
setTextRenderingMode
public PdfCanvas setTextRenderingMode(int textRenderingMode)
Sets text rendering mode.- Parameters:
textRenderingMode- text rendering mode @see PdfCanvasConstants.- Returns:
- current canvas.
-
setTextRise
public PdfCanvas setTextRise(float textRise)
Sets the text rise parameter.
This allows to write text in subscript or superscript mode.- Parameters:
textRise- a parameter- Returns:
- current canvas.
-
setWordSpacing
public PdfCanvas setWordSpacing(float wordSpacing)
Sets the word spacing parameter.- Parameters:
wordSpacing- a parameter- Returns:
- current canvas.
-
setCharacterSpacing
public PdfCanvas setCharacterSpacing(float charSpacing)
Sets the character spacing parameter.- Parameters:
charSpacing- a parameter- Returns:
- current canvas.
-
setHorizontalScaling
public PdfCanvas setHorizontalScaling(float scale)
Sets the horizontal scaling parameter.- Parameters:
scale- a parameter.- Returns:
- current canvas.
-
setTextMatrix
public PdfCanvas setTextMatrix(float a, float b, float c, float d, float x, float y)
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
public PdfCanvas setTextMatrix(AffineTransform transform)
Replaces the text matrix. Contrast withconcatMatrix(double, double, double, double, double, double)- Parameters:
transform- new textmatrix as transformation- Returns:
- current canvas
-
setTextMatrix
public PdfCanvas setTextMatrix(float x, float y)
Changes the text matrix.- Parameters:
x- operand 3,1 in the matrix.y- operand 3,2 in the matrix.- Returns:
- current canvas.
-
showText
public PdfCanvas showText(java.lang.String text)
Shows text (operator Tj).- Parameters:
text- text to show.- Returns:
- current canvas.
-
showText
public PdfCanvas showText(GlyphLine text)
Shows text (operator Tj).- Parameters:
text- text to show.- Returns:
- current canvas.
-
showText
public PdfCanvas showText(GlyphLine text, java.util.Iterator<GlyphLine.GlyphLinePart> iterator)
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.
-
setDrawingOnPage
public void setDrawingOnPage(boolean drawingOnPage)
Sets whether we are currently drawing on a page.- Parameters:
drawingOnPage-trueif we are currently drawing on pagefalseif not
-
getSubrangeWidth
private float getSubrangeWidth(GlyphLine text, int from, int to)
Finds horizontal distance between the start of the `from` glyph and end of `to` glyph. Glyphs with placement are ignored. XAdvance is not taken into account neither before `from` nor after `to` glyphs.
-
getSubrangeYDelta
private float getSubrangeYDelta(GlyphLine text, int from, int to)
-
getWordSpacingAddition
private float getWordSpacingAddition(Glyph glyph)
-
showText
public PdfCanvas showText(PdfArray textArray)
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
public PdfCanvas moveTo(double x, double y)
Move the current point (x, y), omitting any connecting line segment.- Parameters:
x- x coordinate.y- y coordinate.- Returns:
- current canvas.
-
lineTo
public PdfCanvas lineTo(double x, double y)
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
public PdfCanvas 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.- 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
public PdfCanvas curveTo(double x2, double y2, double x3, double y3)
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
public PdfCanvas curveFromTo(double x1, double y1, double x3, double y3)
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
public PdfCanvas 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. 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 rectangley1- a corner of the enclosing rectanglex2- a corner of the enclosing rectangley2- a corner of the enclosing rectanglestartAng- starting angle in degreesextent- angle extent in degrees- Returns:
- the current canvas
-
ellipse
public PdfCanvas ellipse(double x1, double y1, double x2, double y2)
Draws an ellipse inscribed within the rectangle x1,y1,x2,y2.- Parameters:
x1- a corner of the enclosing rectangley1- a corner of the enclosing rectanglex2- a corner of the enclosing rectangley2- a corner of the enclosing rectangle- Returns:
- current canvas.
-
bezierArc
public static java.util.List<double[]> bezierArc(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
public PdfCanvas rectangle(double x, double y, double width, double height)
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
public PdfCanvas rectangle(Rectangle rectangle)
Draws a rectangle.- Parameters:
rectangle- a rectangle to be drawn- Returns:
- current canvas.
-
roundRectangle
public PdfCanvas roundRectangle(double x, double y, double width, double height, double radius)
Draws rounded rectangle.- Parameters:
x- x coordinate of the starting pointy- y coordinate of the starting pointwidth- widthheight- heightradius- radius of the arc corner- Returns:
- current canvas
-
roundRectangle
public PdfCanvas roundRectangle(double x, double y, double width, double height, double rx, double ry, AffineTransform transform)
Draws rounded rectangle.- Parameters:
x- x coordinate of the starting pointy- y coordinate of the starting pointwidth- widthheight- heightrx- x radius of the arc cornerry- y radius of the arc cornertransform-AffineTransformto apply before drawing, ornullin case transform shouldn't be applied- Returns:
- current canvas
-
circle
public PdfCanvas circle(double x, double y, double r)
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
public PdfCanvas paintShading(AbstractPdfShading shading)
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
public PdfCanvas 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
public PdfCanvas closePathEoFillStroke()
Closes the path, fills it using the even-odd rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
closePathFillStroke
public PdfCanvas 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
public PdfCanvas endPath()
Ends the path without filling or stroking it.- Returns:
- current canvas.
-
stroke
public PdfCanvas stroke()
Strokes the path.- Returns:
- current canvas.
-
clip
public PdfCanvas 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
public PdfCanvas 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
public PdfCanvas closePathStroke()
Closes the path and strokes it.- Returns:
- current canvas.
-
fill
public PdfCanvas fill()
Fills current path.- Returns:
- current canvas.
-
fillStroke
public PdfCanvas fillStroke()
Fills the path using the non-zero winding number rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
eoFill
public PdfCanvas eoFill()
EOFills current path.- Returns:
- current canvas.
-
eoFillStroke
public PdfCanvas eoFillStroke()
Fills the path, using the even-odd rule to determine the region to fill and strokes it.- Returns:
- current canvas.
-
setLineWidth
public PdfCanvas setLineWidth(float lineWidth)
Sets line width.- Parameters:
lineWidth- line width.- Returns:
- current canvas.
-
setLineCapStyle
public PdfCanvas setLineCapStyle(int lineCapStyle)
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:
for possible values.
-
setLineJoinStyle
public PdfCanvas setLineJoinStyle(int lineJoinStyle)
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:
for possible values.
-
setMiterLimit
public PdfCanvas 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.- Parameters:
miterLimit- a miter limit to be set- Returns:
- current canvas.
-
setLineDash
public PdfCanvas setLineDash(float phase)
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
public PdfCanvas setLineDash(float unitsOn, float phase)
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 phaseunitsOn- the number of units that must be 'on' (equals the number of units that must be 'off').- Returns:
- current canvas.
-
setLineDash
public PdfCanvas setLineDash(float unitsOn, float unitsOff, float phase)
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 phaseunitsOn- the number of units that must be 'on'unitsOff- the number of units that must be 'off'- Returns:
- current canvas.
-
setLineDash
public PdfCanvas setLineDash(float[] array, float phase)
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 gapsphase- the value of the phase- Returns:
- current canvas.
-
setRenderingIntent
public PdfCanvas setRenderingIntent(PdfName renderingIntent)
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
public PdfCanvas setFlatnessTolerance(float flatnessTolerance)
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
public PdfCanvas setFillColor(Color color)
Changes the current color for filling paths.- Parameters:
color- fill color.- Returns:
- current canvas.
-
setStrokeColor
public PdfCanvas setStrokeColor(Color color)
Changes the current color for stroking paths.- Parameters:
color- stroke color.- Returns:
- current canvas.
-
setColor
public PdfCanvas setColor(Color color, boolean fill)
Changes the current color for paths.- Parameters:
color- the new color.fill- set fill color (true) or stroke color (false)- Returns:
- current canvas.
-
setColor
public PdfCanvas setColor(PdfColorSpace colorSpace, float[] colorValue, boolean fill)
Changes the current color for paths.- Parameters:
colorSpace- the color space of the new colorcolorValue- 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 colorcolorValue- 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 areafill- set fill color (true) or stroke color (false)- Returns:
- current canvas.
-
setFillColorGray
public PdfCanvas setFillColorGray(float g)
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
public PdfCanvas setStrokeColorGray(float g)
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
public PdfCanvas resetFillColorGray()
Changes the current color for filling paths to black.- Returns:
- current canvas.
-
resetStrokeColorGray
public PdfCanvas resetStrokeColorGray()
Changes the current color for stroking paths to black.- Returns:
- current canvas.
-
setFillColorRgb
public PdfCanvas setFillColorRgb(float r, float g, float b)
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
public PdfCanvas setStrokeColorRgb(float r, float g, float b)
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
public PdfCanvas setFillColorShading(PdfPattern.Shading shading)
Adds or changes the shading of the current fill color path.- Parameters:
shading- the shading- Returns:
- current canvas.
-
setStrokeColorShading
public PdfCanvas setStrokeColorShading(PdfPattern.Shading shading)
Adds or changes the shading of the current stroke color path.- Parameters:
shading- the shading- Returns:
- current canvas.
-
resetFillColorRgb
public PdfCanvas resetFillColorRgb()
Changes the current color for filling paths to black.- Returns:
- current canvas.
-
resetStrokeColorRgb
public PdfCanvas resetStrokeColorRgb()
Changes the current color for stroking paths to black.- Returns:
- current canvas.
-
setFillColorCmyk
public PdfCanvas setFillColorCmyk(float c, float m, float y, float k)
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
public PdfCanvas setStrokeColorCmyk(float c, float m, float y, float k)
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
public PdfCanvas resetFillColorCmyk()
Changes the current color for filling paths to black.- Returns:
- current canvas.
-
resetStrokeColorCmyk
public PdfCanvas resetStrokeColorCmyk()
Changes the current color for stroking paths to black.- Returns:
- current canvas.
-
beginLayer
public PdfCanvas beginLayer(IPdfOCG layer)
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
public PdfCanvas 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)
CreatesPdfImageXObjectfrom image and adds it to canvas.The float arguments will be used in concatenating the transformation matrix as operands.
- Parameters:
image- the image from whichPdfImageXObjectwill be createda- an element of the transformation matrixb- an element of the transformation matrixc- an element of the transformation matrixd- an element of the transformation matrixe- an element of the transformation matrixf- an element of the transformation matrix- Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
- See Also:
concatMatrix(double, double, double, double, double, double)
-
addImageWithTransformationMatrix
public PdfXObject addImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f, boolean asInline)
CreatesPdfImageXObjectfrom image and adds it to canvas.The float arguments will be used in concatenating the transformation matrix as operands.
- Parameters:
image- the image from whichPdfImageXObjectwill be createda- an element of the transformation matrixb- an element of the transformation matrixc- an element of the transformation matrixd- an element of the transformation matrixe- an element of the transformation matrixf- an element of the transformation matrixasInline- true if to add image as in-line- Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
- See Also:
concatMatrix(double, double, double, double, double, double)
-
addImageFittedIntoRectangle
public PdfXObject addImageFittedIntoRectangle(ImageData image, Rectangle rect, boolean asInline)
CreatesPdfImageXObjectfrom 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 whichPdfImageXObjectwill be createdrect- the rectangle in which the created imageXObject will be fitasInline- true if to add image as in-line- Returns:
- the created imageXObject or null in case of in-line image (asInline = true)
- See Also:
concatMatrix(double, double, double, double, double, double),PdfXObject.calculateProportionallyFitRectangleWithWidth(PdfXObject, float, float, float),PdfXObject.calculateProportionallyFitRectangleWithHeight(PdfXObject, float, float, float)
-
addImageAt
public PdfXObject addImageAt(ImageData image, float x, float y, boolean asInline)
CreatesPdfImageXObjectfrom image and adds it to the specified position.- Parameters:
image- the image from whichPdfImageXObjectwill be createdx- the horizontal position of the imageXObjecty- the vertical position of the imageXObjectasInline- 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)
AddsPdfXObjectto canvas.The float arguments will be used in concatenating the transformation matrix as operands.
- Parameters:
xObject- the xObject to adda- an element of the transformation matrixb- an element of the transformation matrixc- an element of the transformation matrixd- an element of the transformation matrixe- an element of the transformation matrixf- an element of the transformation matrix- Returns:
- the current canvas
- See Also:
concatMatrix(double, double, double, double, double, double)
-
addXObjectAt
public PdfCanvas addXObjectAt(PdfXObject xObject, float x, float y)
AddsPdfXObjectto the specified position.- Parameters:
xObject- the xObject to addx- the horizontal position of the xObjecty- the vertical position of the xObject- Returns:
- the current canvas
-
addXObjectFittedIntoRectangle
public PdfCanvas addXObjectFittedIntoRectangle(PdfXObject xObject, Rectangle rect)
AddsPdfXObjectfitted into specific rectangle on canvas.- Parameters:
xObject- the xObject to addrect- the rectangle in which the xObject will be fitted- Returns:
- the current canvas
- See Also:
PdfXObject.calculateProportionallyFitRectangleWithWidth(PdfXObject, float, float, float),PdfXObject.calculateProportionallyFitRectangleWithHeight(PdfXObject, float, float, float)
-
addXObject
public PdfCanvas addXObject(PdfXObject xObject)
AddsPdfXObjecton canvas.Note: the
PdfImageXObjectwill be placed at coordinates (0, 0) with its original width and height, thePdfFormXObjectwill be fitted in its bBox.- Parameters:
xObject- the xObject to add- Returns:
- the current canvas
-
setExtGState
public PdfCanvas setExtGState(PdfExtGState extGState)
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
public PdfExtGState setExtGState(PdfDictionary extGState)
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
public PdfCanvas beginMarkedContent(PdfName tag)
Manually start a Marked Content sequence. Used primarily for Tagged PDF- Parameters:
tag- the type of content contained- Returns:
- current canvas
-
beginMarkedContent
public PdfCanvas beginMarkedContent(PdfName tag, PdfDictionary properties)
Manually start a Marked Content sequence with properties. Used primarily for Tagged PDF- Parameters:
tag- the type of content that will be containedproperties- the properties of the content, including Marked Content ID. If null, the PDF marker is BMC, else it is BDC- Returns:
- current canvas
-
endMarkedContent
public PdfCanvas endMarkedContent()
Manually end a Marked Content sequence. Used primarily for Tagged PDF- Returns:
- current canvas
-
openTag
public PdfCanvas openTag(CanvasTag tag)
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
public PdfCanvas openTag(TagReference tagReference)
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
public PdfCanvas closeTag()
Manually close a tag, ending a Marked Content sequence. Used primarily for Tagged PDF- Returns:
- current canvas
-
writeLiteral
public PdfCanvas writeLiteral(java.lang.String s)
Outputs aStringdirectly to the content.- Parameters:
s- theString- Returns:
- current canvas.
-
writeLiteral
public PdfCanvas writeLiteral(char c)
Outputs achardirectly to the content.- Parameters:
c- thechar- Returns:
- current canvas.
-
writeLiteral
public PdfCanvas writeLiteral(float n)
Outputs afloatdirectly to the content.- Parameters:
n- thefloat- Returns:
- current canvas.
-
getContentStream
public PdfStream 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)
AddsPdfImageXObjectto canvas.- Parameters:
imageXObject- thePdfImageXObjectobjecta- an element of the transformation matrixb- an element of the transformation matrixc- an element of the transformation matrixd- an element of the transformation matrixe- an element of the transformation matrixf- an element of the transformation matrix
-
saveColorSpaceToPageResourcesIfNeeded
private void saveColorSpaceToPageResourcesIfNeeded(PdfStream image)
-
addFormWithTransformationMatrix
private PdfCanvas addFormWithTransformationMatrix(PdfFormXObject form, float a, float b, float c, float d, float e, float f, boolean writeIdentityMatrix)
AddsPdfFormXObjectto canvas.- Parameters:
form- the formXObject to adda- an element of the transformation matrixb- an element of the transformation matrixc- an element of the transformation matrixd- an element of the transformation matrixe- an element of the transformation matrixf- an element of the transformation matrixwriteIdentityMatrix- true if the matrix is written in any case, otherwise if theisIdentityMatrix(float, float, float, float, float, float)method indicates that the matrix is identity, the matrix will not be written- Returns:
- current canvas
-
addFormAt
private PdfCanvas addFormAt(PdfFormXObject form, float x, float y)
AddsPdfFormXObjectto the specified position.- Parameters:
form- the formXObject to addx- the horizontal position of the formXObjecty- the vertical position of the formXObject- Returns:
- the current canvas
-
addFormFittedIntoRectangle
private PdfCanvas addFormFittedIntoRectangle(PdfFormXObject form, Rectangle rect)
AddsPdfFormXObjectfitted into specific rectangle on canvas.- Parameters:
form- the formXObject to addrect- the rectangle in which the formXObject will be fitted- Returns:
- the current canvas
-
addImageWithTransformationMatrix
private PdfCanvas addImageWithTransformationMatrix(PdfXObject xObject, float a, float b, float c, float d, float e, float f)
AddsPdfXObjectto canvas.- Parameters:
xObject- the xObject to adda- an element of the transformation matrixb- an element of the transformation matrixc- an element of the transformation matrixd- an element of the transformation matrixe- an element of the transformation matrixf- an element of the transformation matrix- Returns:
- current canvas
-
addImageAt
private PdfCanvas addImageAt(PdfImageXObject image, float x, float y)
AddsPdfImageXObjectto the specified position.- Parameters:
image- the imageXObject to addx- the horizontal position of the imageXObjecty- the vertical position of the imageXObject- Returns:
- the current canvas
-
addImageFittedIntoRectangle
private PdfCanvas addImageFittedIntoRectangle(PdfImageXObject image, Rectangle rect)
AddsPdfImageXObjectfitted into specific rectangle on canvas.- Parameters:
image- the imageXObject to addrect- the rectangle in which the imageXObject will be fitted- Returns:
- current canvas
-
ensureStreamDataIsReadyToBeProcessed
private PdfStream ensureStreamDataIsReadyToBeProcessed(PdfStream stream)
-
showTextInt
private void showTextInt(java.lang.String text)
A helper to insert into the content stream thetextconverted to bytes according to the font's encoding.- Parameters:
text- the text to write.
-
checkIsoConformanceWritingOnContent
private void checkIsoConformanceWritingOnContent()
-
addToPropertiesAndBeginLayer
private void addToPropertiesAndBeginLayer(IPdfOCG layer)
-
createColor
private Color createColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern)
-
getDashPatternArray
private PdfArray getDashPatternArray(float phase)
-
getDashPatternArray
private PdfArray getDashPatternArray(float[] dashArray, float phase)
-
applyRotation
private void applyRotation(PdfPage page)
-
drawArc
private PdfCanvas drawArc(double x1, double y1, double x2, double y2, double startAng, double extent, boolean continuous)
-
checkDefaultDeviceGrayBlackColor
private void checkDefaultDeviceGrayBlackColor(PdfCanvas.CheckColorMode checkColorMode)
-
getColorKeyForText
private PdfCanvas.CheckColorMode getColorKeyForText()
-
iteratorToList
private static <T> java.util.List<T> iteratorToList(java.util.Iterator<T> iterator)
-
calculateTransformationMatrix
private static float[] calculateTransformationMatrix(Vector expectedMin, Vector expectedMax, Vector actualMin, Vector actualMax)
-
isIdentityMatrix
private static boolean isIdentityMatrix(float a, float b, float c, float d, float e, float f)
-
getEllipseRoundedRectPoints
private static double[] getEllipseRoundedRectPoints(double x, double y, double width, double height, double rx, double ry)
-
checkTextOnAddition
private void checkTextOnAddition(GlyphLine text)
-
checkTextOnAddition
private void checkTextOnAddition(java.lang.String text)
-
-