abstract class PDAbstractContentStream
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
protected PDDocument |
document |
protected java.util.Deque<PDFont> |
fontStack |
private byte[] |
formatBuffer |
private java.text.NumberFormat |
formatDecimal |
protected boolean |
inTextMode |
private static org.apache.commons.logging.Log |
LOG |
protected java.util.Deque<PDColorSpace> |
nonStrokingColorSpaceStack |
protected java.io.OutputStream |
outputStream |
protected PDResources |
resources |
protected java.util.Deque<PDColorSpace> |
strokingColorSpaceStack |
Constructor and Description |
---|
PDAbstractContentStream(PDDocument document,
java.io.OutputStream outputStream,
PDResources resources)
Create a new appearance stream.
|
Modifier and Type | Method and Description |
---|---|
void |
addComment(java.lang.String comment)
Write a comment line.
|
void |
addRect(float x,
float y,
float width,
float height)
Add a rectangle to the current path.
|
void |
beginMarkedContent(COSName tag)
Begin a marked content sequence.
|
void |
beginMarkedContent(COSName tag,
PDPropertyList propertyList)
Begin a marked content sequence with a reference to an entry in the page resources'
Properties dictionary.
|
void |
beginText()
Begin some text operations.
|
void |
clip()
Intersects the current clipping path with the current path, using the nonzero rule.
|
void |
clipEvenOdd()
Intersects the current clipping path with the current path, using the even-odd rule.
|
void |
close()
Close the content stream.
|
void |
closeAndFillAndStroke()
Close, fill, and then stroke the path, using the nonzero winding number rule to determine the
region to fill.
|
void |
closeAndFillAndStrokeEvenOdd()
Close, fill, and then stroke the path, using the even-odd rule to determine the region to
fill.
|
void |
closeAndStroke()
Close and stroke the path.
|
void |
closePath()
Closes the current subpath.
|
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Append a cubic Bézier curve to the current path.
|
void |
curveTo1(float x1,
float y1,
float x3,
float y3)
Append a cubic Bézier curve to the current path.
|
void |
curveTo2(float x2,
float y2,
float x3,
float y3)
Append a cubic Bézier curve to the current path.
|
void |
drawForm(PDFormXObject form)
Draws the given Form XObject at the current location.
|
void |
drawImage(PDImageXObject image,
float x,
float y)
Draw an image at the x,y coordinates, with the default size of the image.
|
void |
drawImage(PDImageXObject image,
float x,
float y,
float width,
float height)
Draw an image at the x,y coordinates, with the given size.
|
void |
drawImage(PDImageXObject image,
Matrix matrix)
Draw an image at the origin with the given transformation matrix.
|
void |
drawImage(PDInlineImage inlineImage,
float x,
float y)
Draw an inline image at the x,y coordinates, with the default size of the image.
|
void |
drawImage(PDInlineImage inlineImage,
float x,
float y,
float width,
float height)
Draw an inline image at the x,y coordinates and a certain width and height.
|
void |
endMarkedContent()
End a marked content sequence.
|
void |
endText()
End some text operations.
|
void |
fill()
Fills the path using the nonzero winding number rule.
|
void |
fillAndStroke()
Fill and then stroke the path, using the nonzero winding number rule to determine the region
to fill.
|
void |
fillAndStrokeEvenOdd()
Fill and then stroke the path, using the even-odd rule to determine the region to
fill.
|
void |
fillEvenOdd()
Fills the path using the even-odd winding rule.
|
protected COSName |
getName(PDColorSpace colorSpace) |
protected boolean |
isOutside255Interval(int val) |
private boolean |
isOutsideOneInterval(double val) |
void |
lineTo(float x,
float y)
Draw a line from the current position to the given coordinates.
|
void |
moveTo(float x,
float y)
Move the current position to the given coordinates.
|
void |
newLine()
Move to the start of the next line of text.
|
void |
newLineAtOffset(float tx,
float ty)
The Td operator.
|
void |
restoreGraphicsState()
Q operator.
|
void |
saveGraphicsState()
q operator.
|
void |
setCharacterSpacing(float spacing)
Set the character spacing.
|
void |
setFont(PDFont font,
float fontSize)
Set the font and font size to draw text with.
|
void |
setGraphicsStateParameters(PDExtendedGraphicsState state)
Set an extended graphics state.
|
void |
setHorizontalScaling(float scale)
Set the horizontal scaling to scale / 100.
|
void |
setLeading(float leading)
Sets the text leading.
|
void |
setLineCapStyle(int lineCapStyle)
Set the line cap style.
|
void |
setLineDashPattern(float[] pattern,
float phase)
Set the line dash pattern.
|
void |
setLineJoinStyle(int lineJoinStyle)
Set the line join style.
|
void |
setLineWidth(float lineWidth)
Set line width to the given value.
|
protected void |
setMaximumFractionDigits(int fractionDigitsNumber)
Sets the maximum number of digits allowed for fractional numbers.
|
void |
setMiterLimit(float miterLimit)
Set the miter limit.
|
void |
setNonStrokingColor(java.awt.Color color)
Set the non-stroking color using an AWT color.
|
void |
setNonStrokingColor(float g)
Set the non-stroking color in the DeviceGray color space.
|
void |
setNonStrokingColor(float r,
float g,
float b)
Set the non-stroking color in the DeviceRGB color space.
|
void |
setNonStrokingColor(float c,
float m,
float y,
float k)
Set the non-stroking color in the DeviceCMYK color space.
|
void |
setNonStrokingColor(int g)
Deprecated.
|
void |
setNonStrokingColor(int r,
int g,
int b)
Deprecated.
|
void |
setNonStrokingColor(int c,
int m,
int y,
int k)
Set the non-stroking color in the DeviceCMYK color space.
|
void |
setNonStrokingColor(PDColor color)
Sets the non-stroking color and, if necessary, the non-stroking color space.
|
protected void |
setNonStrokingColorSpaceStack(PDColorSpace colorSpace) |
void |
setRenderingMode(RenderingMode rm)
Set the text rendering mode.
|
void |
setStrokingColor(java.awt.Color color)
Set the stroking color using an AWT color.
|
void |
setStrokingColor(float g)
Set the stroking color in the DeviceGray color space.
|
void |
setStrokingColor(float r,
float g,
float b)
Set the stroking color in the DeviceRGB color space.
|
void |
setStrokingColor(float c,
float m,
float y,
float k)
Set the stroking color in the DeviceCMYK color space.
|
void |
setStrokingColor(int r,
int g,
int b)
Deprecated.
|
void |
setStrokingColor(PDColor color)
Sets the stroking color and, if necessary, the stroking color space.
|
protected void |
setStrokingColorSpaceStack(PDColorSpace colorSpace) |
void |
setTextMatrix(Matrix matrix)
The Tm operator.
|
void |
setTextRise(float rise)
Set the text rise value, i.e.
|
void |
setWordSpacing(float spacing)
Set the word spacing.
|
void |
shadingFill(PDShading shading)
Fills the clipping area with the given shading.
|
void |
showText(java.lang.String text)
Shows the given text at the location specified by the current text matrix.
|
protected void |
showTextInternal(java.lang.String text)
Outputs a string using the correct encoding and subsetting as required.
|
void |
showTextWithPositioning(java.lang.Object[] textWithPositioningArray)
Shows the given text at the location specified by the current text matrix with the given
interspersed positioning.
|
void |
stroke()
Stroke the path.
|
void |
transform(Matrix matrix)
The cm operator.
|
protected void |
write(byte[] data)
Writes a byte[] to the content stream.
|
protected void |
write(java.lang.String text)
Writes a string to the content stream as ASCII.
|
private void |
writeAffineTransform(java.awt.geom.AffineTransform transform)
Writes an AffineTransform to the content stream as an array.
|
protected void |
writeBytes(byte[] data)
Writes binary data to the content stream.
|
protected void |
writeLine()
Writes a newline to the content stream as ASCII.
|
protected void |
writeOperand(COSName name)
Writes a COSName to the content stream.
|
protected void |
writeOperand(float real)
Writes a real number to the content stream.
|
protected void |
writeOperand(int integer)
Writes an integer number to the content stream.
|
protected void |
writeOperator(java.lang.String text)
Writes a string to the content stream as ASCII.
|
private static final org.apache.commons.logging.Log LOG
protected final PDDocument document
protected final java.io.OutputStream outputStream
protected final PDResources resources
protected boolean inTextMode
protected final java.util.Deque<PDFont> fontStack
protected final java.util.Deque<PDColorSpace> nonStrokingColorSpaceStack
protected final java.util.Deque<PDColorSpace> strokingColorSpaceStack
private final java.text.NumberFormat formatDecimal
private final byte[] formatBuffer
PDAbstractContentStream(PDDocument document, java.io.OutputStream outputStream, PDResources resources)
document
- may be nulloutputStream
- The appearances output stream to write to.resources
- The resources to useprotected void setMaximumFractionDigits(int fractionDigitsNumber)
fractionDigitsNumber
- NumberFormat.setMaximumFractionDigits(int)
public void beginText() throws java.io.IOException
java.io.IOException
- If there is an error writing to the stream or if you attempt to
nest beginText calls.java.lang.IllegalStateException
- If the method was not allowed to be called at this time.public void endText() throws java.io.IOException
java.io.IOException
- If there is an error writing to the stream or if you attempt to
nest endText calls.java.lang.IllegalStateException
- If the method was not allowed to be called at this time.public void setFont(PDFont font, float fontSize) throws java.io.IOException
font
- The font to use.fontSize
- The font size to draw the text.java.io.IOException
- If there is an error writing the font information.public void showTextWithPositioning(java.lang.Object[] textWithPositioningArray) throws java.io.IOException
textWithPositioningArray
- An array consisting of String and Float types. Each String is
output to the page using the current text matrix. Using the default coordinate system, each
interspersed number adjusts the current text matrix by translating to the left or down for
horizontal and vertical text respectively. The number is expressed in thousands of a text
space unit, and may be negative.java.io.IOException
- if an io exception occurs.public void showText(java.lang.String text) throws java.io.IOException
text
- The Unicode text to show.java.io.IOException
- If an io exception occurs.java.lang.IllegalArgumentException
- if a character isn't supported by the current fontprotected void showTextInternal(java.lang.String text) throws java.io.IOException
text
- The Unicode text to show.java.io.IOException
- If an io exception occurs.public void setLeading(float leading) throws java.io.IOException
leading
- The leading in unscaled text units.java.io.IOException
- If there is an error writing to the stream.public void newLine() throws java.io.IOException
setLeading(float)
)
to have been set.java.io.IOException
- If there is an error writing to the stream.public void newLineAtOffset(float tx, float ty) throws java.io.IOException
tx
- The x translation.ty
- The y translation.java.io.IOException
- If there is an error writing to the stream.java.lang.IllegalStateException
- If the method was not allowed to be called at this time.public void setTextMatrix(Matrix matrix) throws java.io.IOException
matrix
- the transformation matrixjava.io.IOException
- If there is an error writing to the stream.java.lang.IllegalStateException
- If the method was not allowed to be called at this time.public void drawImage(PDImageXObject image, float x, float y) throws java.io.IOException
image
- The image to draw.x
- The x-coordinate to draw the image.y
- The y-coordinate to draw the image.java.io.IOException
- If there is an error writing to the stream.public void drawImage(PDImageXObject image, float x, float y, float width, float height) throws java.io.IOException
image
- The image to draw.x
- The x-coordinate to draw the image.y
- The y-coordinate to draw the image.width
- The width to draw the image.height
- The height to draw the image.java.io.IOException
- If there is an error writing to the stream.java.lang.IllegalStateException
- If the method was called within a text block.public void drawImage(PDImageXObject image, Matrix matrix) throws java.io.IOException
image
- The image to draw.matrix
- The transformation matrix to apply to the image.java.io.IOException
- If there is an error writing to the stream.java.lang.IllegalStateException
- If the method was called within a text block.public void drawImage(PDInlineImage inlineImage, float x, float y) throws java.io.IOException
inlineImage
- The inline image to draw.x
- The x-coordinate to draw the inline image.y
- The y-coordinate to draw the inline image.java.io.IOException
- If there is an error writing to the stream.public void drawImage(PDInlineImage inlineImage, float x, float y, float width, float height) throws java.io.IOException
inlineImage
- The inline image to draw.x
- The x-coordinate to draw the inline image.y
- The y-coordinate to draw the inline image.width
- The width of the inline image to draw.height
- The height of the inline image to draw.java.io.IOException
- If there is an error writing to the stream.java.lang.IllegalStateException
- If the method was called within a text block.public void drawForm(PDFormXObject form) throws java.io.IOException
form
- Form XObjectjava.io.IOException
- if the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void transform(Matrix matrix) throws java.io.IOException
matrix
- the transformation matrixjava.io.IOException
- If there is an error writing to the stream.public void saveGraphicsState() throws java.io.IOException
java.io.IOException
- If an error occurs while writing to the stream.public void restoreGraphicsState() throws java.io.IOException
java.io.IOException
- If an error occurs while writing to the stream.protected COSName getName(PDColorSpace colorSpace)
public void setStrokingColor(PDColor color) throws java.io.IOException
color
- Color in a specific color space.java.io.IOException
- If an IO error occurs while writing to the stream.public void setStrokingColor(java.awt.Color color) throws java.io.IOException
color
- The color to set.java.io.IOException
- If an IO error occurs while writing to the stream.public void setStrokingColor(float r, float g, float b) throws java.io.IOException
r
- The red valueg
- The green value.b
- The blue value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameters are invalid.@Deprecated public void setStrokingColor(int r, int g, int b) throws java.io.IOException
setStrokingColor(r/255f, g/255f, b/255f)
r
- The red valueg
- The green value.b
- The blue value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameters are invalid.public void setStrokingColor(float c, float m, float y, float k) throws java.io.IOException
c
- The cyan value.m
- The magenta value.y
- The yellow value.k
- The black value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameters are invalid.public void setStrokingColor(float g) throws java.io.IOException
g
- The gray value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameter is invalid.public void setNonStrokingColor(PDColor color) throws java.io.IOException
color
- Color in a specific color space.java.io.IOException
- If an IO error occurs while writing to the stream.public void setNonStrokingColor(java.awt.Color color) throws java.io.IOException
color
- The color to set.java.io.IOException
- If an IO error occurs while writing to the stream.public void setNonStrokingColor(float r, float g, float b) throws java.io.IOException
r
- The red value.g
- The green value.b
- The blue value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameters are invalid.@Deprecated public void setNonStrokingColor(int r, int g, int b) throws java.io.IOException
setNonStrokingColor(r/255f, g/255f, b/255f)
r
- The red valueg
- The green value.b
- The blue value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameters are invalid.public void setNonStrokingColor(int c, int m, int y, int k) throws java.io.IOException
c
- The cyan value.m
- The magenta value.y
- The yellow value.k
- The black value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameters are invalid.public void setNonStrokingColor(float c, float m, float y, float k) throws java.io.IOException
c
- The cyan value.m
- The magenta value.y
- The yellow value.k
- The black value.java.io.IOException
- If an IO error occurs while writing to the stream.public void setNonStrokingColor(int g) throws java.io.IOException
setNonStrokingColor(g/255f)
g
- The gray value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameter is invalid.public void setNonStrokingColor(float g) throws java.io.IOException
g
- The gray value.java.io.IOException
- If an IO error occurs while writing to the stream.java.lang.IllegalArgumentException
- If the parameter is invalid.public void addRect(float x, float y, float width, float height) throws java.io.IOException
x
- The lower left x coordinate.y
- The lower left y coordinate.width
- The width of the rectangle.height
- The height of the rectangle.java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws java.io.IOException
x1
- x coordinate of the point 1y1
- y coordinate of the point 1x2
- x coordinate of the point 2y2
- y coordinate of the point 2x3
- x coordinate of the point 3y3
- y coordinate of the point 3java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.public void curveTo2(float x2, float y2, float x3, float y3) throws java.io.IOException
x2
- x coordinate of the point 2y2
- y coordinate of the point 2x3
- x coordinate of the point 3y3
- y coordinate of the point 3java.lang.IllegalStateException
- If the method was called within a text block.java.io.IOException
- If the content stream could not be written.public void curveTo1(float x1, float y1, float x3, float y3) throws java.io.IOException
x1
- x coordinate of the point 1y1
- y coordinate of the point 1x3
- x coordinate of the point 3y3
- y coordinate of the point 3java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.public void moveTo(float x, float y) throws java.io.IOException
x
- The x coordinate.y
- The y coordinate.java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.public void lineTo(float x, float y) throws java.io.IOException
x
- The x coordinate.y
- The y coordinate.java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.public void stroke() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void closeAndStroke() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void fill() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void fillEvenOdd() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void fillAndStroke() throws java.io.IOException
fill()
and the second with stroke()
.java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void fillAndStrokeEvenOdd() throws java.io.IOException
fillEvenOdd()
and the second with stroke()
.java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void closeAndFillAndStroke() throws java.io.IOException
closePath()
and then fillAndStroke()
.java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void closeAndFillAndStrokeEvenOdd() throws java.io.IOException
closePath()
and then fillAndStrokeEvenOdd()
.java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void shadingFill(PDShading shading) throws java.io.IOException
shading
- Shading resourcejava.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void closePath() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void clip() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void clipEvenOdd() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void setLineWidth(float lineWidth) throws java.io.IOException
lineWidth
- The width which is used for drawing.java.io.IOException
- If the content stream could not be writtenjava.lang.IllegalStateException
- If the method was called within a text block.public void setLineJoinStyle(int lineJoinStyle) throws java.io.IOException
lineJoinStyle
- 0 for miter join, 1 for round join, and 2 for bevel join.java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.java.lang.IllegalArgumentException
- If the parameter is not a valid line join style.public void setLineCapStyle(int lineCapStyle) throws java.io.IOException
lineCapStyle
- 0 for butt cap, 1 for round cap, and 2 for projecting square cap.java.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.java.lang.IllegalArgumentException
- If the parameter is not a valid line cap style.public void setLineDashPattern(float[] pattern, float phase) throws java.io.IOException
pattern
- The pattern arrayphase
- The phase of the patternjava.io.IOException
- If the content stream could not be written.java.lang.IllegalStateException
- If the method was called within a text block.public void setMiterLimit(float miterLimit) throws java.io.IOException
miterLimit
- the new miter limit.java.io.IOException
- If the content stream could not be written.public void beginMarkedContent(COSName tag) throws java.io.IOException
tag
- the tagjava.io.IOException
- If the content stream could not be writtenpublic void beginMarkedContent(COSName tag, PDPropertyList propertyList) throws java.io.IOException
tag
- the tagpropertyList
- property listjava.io.IOException
- If the content stream could not be writtenpublic void endMarkedContent() throws java.io.IOException
java.io.IOException
- If the content stream could not be writtenpublic void setGraphicsStateParameters(PDExtendedGraphicsState state) throws java.io.IOException
state
- The extended graphics state.java.io.IOException
- If the content stream could not be written.public void addComment(java.lang.String comment) throws java.io.IOException
comment
- java.io.IOException
- If the content stream could not be written.java.lang.IllegalArgumentException
- If the comment contains a newline. This is not allowed,
because the next line could be ordinary PDF content.protected void writeOperand(float real) throws java.io.IOException
real
- java.io.IOException
protected void writeOperand(int integer) throws java.io.IOException
integer
- java.io.IOException
protected void writeOperand(COSName name) throws java.io.IOException
name
- java.io.IOException
protected void writeOperator(java.lang.String text) throws java.io.IOException
text
- java.io.IOException
protected void write(java.lang.String text) throws java.io.IOException
text
- java.io.IOException
protected void write(byte[] data) throws java.io.IOException
data
- java.io.IOException
protected void writeLine() throws java.io.IOException
java.io.IOException
protected void writeBytes(byte[] data) throws java.io.IOException
data
- java.io.IOException
private void writeAffineTransform(java.awt.geom.AffineTransform transform) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- If the underlying stream has a problem being written to.protected boolean isOutside255Interval(int val)
private boolean isOutsideOneInterval(double val)
protected void setStrokingColorSpaceStack(PDColorSpace colorSpace)
protected void setNonStrokingColorSpaceStack(PDColorSpace colorSpace)
public void setCharacterSpacing(float spacing) throws java.io.IOException
spacing
- character spacingjava.io.IOException
- If the content stream could not be written.public void setWordSpacing(float spacing) throws java.io.IOException
This will have an effect only with Type1 and TrueType fonts, not with Type0 fonts. The PDF specification tells why: "Word spacing shall be applied to every occurrence of the single-byte character code 32 in a string when using a simple font or a composite font that defines code 32 as a single-byte code. It shall not apply to occurrences of the byte value 32 in multiple-byte codes."
spacing
- word spacingjava.io.IOException
- If the content stream could not be written.public void setHorizontalScaling(float scale) throws java.io.IOException
scale
- number specifying the percentage of the normal width. Default value: 100 (normal
width).java.io.IOException
- If the content stream could not be written.public void setRenderingMode(RenderingMode rm) throws java.io.IOException
rm
- The text rendering mode.java.io.IOException
- If the content stream could not be written.public void setTextRise(float rise) throws java.io.IOException
rise
- Specifies the distance, in unscaled text space units, to move the baseline up or
down from its default location. 0 restores the default location.java.io.IOException