Package net.atthegate.server.service.pdf
Class Page
java.lang.Object
net.atthegate.server.service.pdf.Page
Used to create PDF page objects.
Please note:
The coordinate (0f, 0f) is the top left corner of the page. The size of the pages are represented in points. 1 point is 1/72 inches.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<net.atthegate.server.service.pdf.Annotation>
protected float[]
protected float[]
protected ByteArrayOutputStream
protected float[]
protected List<Destination>
protected float
static final int
static final int
static final int
static final int
static final int
static final int
protected int
protected PDFobj
protected PDF
protected int
protected float
protected List<StructElem>
protected float[]
protected float[]
protected float
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAnnotation
(net.atthegate.server.service.pdf.Annotation annotation) void
void
addDestination
(String name, float yPosition) Adds destination to this page.void
addEMC()
addResource
(CoreFont coreFont, Map<Integer, PDFobj> objects) void
addResource
(Font font, Map<Integer, PDFobj> objects) void
addResource
(Image image, Map<Integer, PDFobj> objects) void
addWatermark
(Font font, String text) protected void
append
(byte b) void
append
(byte[] buffer) Appends the specified array of bytes to the page.protected void
append
(char ch) protected void
append
(float val) protected void
append
(int num) protected void
protected void
beginTransform
(float x, float y, float xScale, float yScale) void
bezierCurveTo
(Point p1, Point p2, Point p3) Draws a bezier curve starting from the current point.void
clipPath()
Clips the path.void
clipRect
(float x, float y, float w, float h) void
Closes the path and draws it using the current pen color.void
void
drawCircle
(double x, double y, double r) Draws a circle on the page.void
drawCircle
(double x, double y, double r, char operation) Draws the specified circle on the page and fills it with the current brush color.void
drawCircle
(float x, float y, float r) Draws a circle on the page.void
drawCircle
(float x, float y, float r, char operation) Draws the specified circle on the page and fills it with the current brush color.void
drawContents
(byte[] content, float h, float x, float y, float xScale, float yScale) void
drawEllipse
(double x, double y, double r1, double r2) Draws an ellipse on the page using the current pen color.void
drawEllipse
(float x, float y, float r1, float r2) Draws an ellipse on the page using the current pen color.void
drawLine
(double x1, double y1, double x2, double y2) Draws a line on the page, using the current color, between the points (x1, y1) and (x2, y2).void
drawLine
(float x1, float y1, float x2, float y2) Draws a line on the page, using the current color, between the points (x1, y1) and (x2, y2).void
Draws or fills the specified path using the current pen or brush.void
Draws a point on the page using the current pen color.void
drawRect
(double x, double y, double w, double h) Draws the outline of the specified rectangle on the page.void
drawRect
(float x, float y, float w, float h) Draws the outline of the specified rectangle on the page.void
drawRectRoundCorners
(float x, float y, float w, float h, float r1, float r2, char operation) void
drawString
(Font font, String str, double x, double y) Draws the text given by the specified string, using the specified font and the current brush color.void
drawString
(Font font, String str, float x, float y) Draws the text given by the specified string, using the specified font and the current brush color.void
drawString
(Font font, String str, float x, float y, float dx) protected void
void
drawString
(Font font1, Font font2, String str, float x, float y) Draws the text given by the specified string, using the specified main font and the current brush color.protected void
void
fillEllipse
(double x, double y, double r1, double r2) Fills an ellipse on the page using the current pen color.void
fillEllipse
(float x, float y, float r1, float r2) Fills an ellipse on the page using the current pen color.void
fillPath()
Closes and fills the path with the current brush color.void
fillRect
(double x, double y, double w, double h) Fills the specified rectangle on the page.void
fillRect
(float x, float y, float w, float h) Fills the specified rectangle on the page.float[]
Returns the brush color.byte[]
float
Returns the height of this page.float
getWidth()
Returns the width of this page.void
void
lineTo
(double x, double y) Draws a line from the current pen position to the point with coordinates (x, y), using the current pen width and stroke color.void
lineTo
(float x, float y) Draws a line from the current pen position to the point with coordinates (x, y), using the current pen width and stroke color.void
moveTo
(double x, double y) Moves the pen to the point with coordinates (x, y) on the page.void
moveTo
(float x, float y) Moves the pen to the point with coordinates (x, y) on the page.void
Prints a line of text.void
println()
Move to the next line.void
Prints a line of text and moves to the next line.void
restore()
void
save()
void
setArtBox
(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page ArtBox.void
setBleedBox
(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page BleedBox.void
setBrushColor
(double r, double g, double b) Sets the color for brush operations.void
setBrushColor
(float[] color) Sets the color for brush operations.void
setBrushColor
(float r, float g, float b) Sets the color for brush operations.void
setBrushColor
(int color) Sets the brush color.void
setCharSpacing
(float spacing) void
setCropBox
(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page CropBox.void
Sets the default line dash pattern - solid line.void
Sets the line width to the default.void
Sets the graphics state.void
setLineCapStyle
(int style) Sets the current line cap style.void
setLineJoinStyle
(int style) Sets the line join style.void
setLinePattern
(String pattern) The line dash pattern controls the pattern of dashes and gaps used to stroke paths.void
setPenColor
(double r, double g, double b) Sets the color for stroking operations.void
setPenColor
(float r, float g, float b) Sets the color for stroking operations.void
setPenColor
(int color) Sets the pen color.void
setPenWidth
(double width) Sets the pen width that will be used to draw lines and splines on this page.void
setPenWidth
(float width) Sets the pen width that will be used to draw lines and splines on this page.protected void
setStructElementsPageObjNumber
(int pageObjNumber) void
setTextBegin
(float x, float y) void
setTextDirection
(int degrees) Sets the text direction.void
Sets the end of text block.void
setTextFont
(Font font) void
setTextLeading
(float leading) Sets the text leading.void
setTextLocation
(float x, float y) Sets the text location.void
setTextRenderingMode
(int mode) Sets the text rendering mode.void
setTextRise
(float rise) void
setTextScaling
(float scaling) void
Sets the start of text block.void
setTrimBox
(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page TrimBox.void
setWordSpacing
(float spacing) void
Draws the path using the current pen color.void
transform
(float[] values) Transformation matrix.
-
Field Details
-
pdf
-
pageObj
-
objNumber
protected int objNumber -
buf
-
tm
protected float[] tm -
renderingMode
protected int renderingMode -
width
protected float width -
height
protected float height -
contents
-
annots
-
destinations
-
cropBox
protected float[] cropBox -
bleedBox
protected float[] bleedBox -
trimBox
protected float[] trimBox -
artBox
protected float[] artBox -
structures
-
savedHeight
protected float savedHeight -
MSCALE_X
public static final int MSCALE_X- See Also:
-
MSKEW_X
public static final int MSKEW_X- See Also:
-
MTRANS_X
public static final int MTRANS_X- See Also:
-
MSKEW_Y
public static final int MSKEW_Y- See Also:
-
MSCALE_Y
public static final int MSCALE_Y- See Also:
-
MTRANS_Y
public static final int MTRANS_Y- See Also:
-
-
Constructor Details
-
Page
Creates page object and add it to the PDF document. Please note:The coordinate (0f, 0f) is the top left corner of the page. The size of the pages are represented in points. 1 point is 1/72 inches.
- Parameters:
pdf
- the pdf object.pageSize
- the page size of this page.- Throws:
Exception
-
Page
Creates page object and add it to the PDF document. Please note:The coordinate (0f, 0f) is the top left corner of the page. The size of the pages are represented in points. 1 point is 1/72 inches.
- Parameters:
pdf
- the pdf object.pageSize
- the page size of this page.addPageToPDF
- boolean flag.- Throws:
Exception
-
Page
- Throws:
Exception
-
-
Method Details
-
addResource
-
addResource
-
addResource
-
complete
- Throws:
Exception
-
getContent
public byte[] getContent() -
addDestination
Adds destination to this page.- Parameters:
name
- The destination name.yPosition
- The vertical position of the destination on this page.- Returns:
- the destination.
-
getWidth
public float getWidth()Returns the width of this page.- Returns:
- the width of the page.
-
getHeight
public float getHeight()Returns the height of this page.- Returns:
- the height of the page.
-
drawLine
Draws a line on the page, using the current color, between the points (x1, y1) and (x2, y2).- Parameters:
x1
- the first point's x coordinate.y1
- the first point's y coordinate.x2
- the second point's x coordinate.y2
- the second point's y coordinate.- Throws:
IOException
-
drawLine
Draws a line on the page, using the current color, between the points (x1, y1) and (x2, y2).- Parameters:
x1
- the first point's x coordinate.y1
- the first point's y coordinate.x2
- the second point's x coordinate.y2
- the second point's y coordinate.- Throws:
IOException
-
drawString
Draws the text given by the specified string, using the specified main font and the current brush color. If the main font is missing some glyphs - the fallback font is used. The baseline of the leftmost character is at position (x, y) on the page.- Parameters:
font1
- the main font.font2
- the fallback font.str
- the string to be drawn.x
- the x coordinate.y
- the y coordinate.- Throws:
IOException
-
drawString
Draws the text given by the specified string, using the specified font and the current brush color. The baseline of the leftmost character is at position (x, y) on the page.- Parameters:
font
- the font to use.str
- the string to be drawn.x
- the x coordinate.y
- the y coordinate.- Throws:
IOException
-
drawString
Draws the text given by the specified string, using the specified font and the current brush color. The baseline of the leftmost character is at position (x, y) on the page.- Parameters:
font
- the font to use.str
- the string to be drawn.x
- the x coordinate.y
- the y coordinate.- Throws:
IOException
-
setGraphicsState
Sets the graphics state. Please see Example_31.- Parameters:
gs
- the graphics state to use.- Throws:
IOException
-
setPenColor
Sets the color for stroking operations. The pen color is used when drawing lines and splines.- Parameters:
r
- the red component is float value from 0.0 to 1.0.g
- the green component is float value from 0.0 to 1.0.b
- the blue component is float value from 0.0 to 1.0.- Throws:
IOException
-
setPenColor
Sets the color for stroking operations. The pen color is used when drawing lines and splines.- Parameters:
r
- the red component is float value from 0.0f to 1.0f.g
- the green component is float value from 0.0f to 1.0f.b
- the blue component is float value from 0.0f to 1.0f.- Throws:
IOException
-
setBrushColor
Sets the color for brush operations. This is the color used when drawing regular text and filling shapes.- Parameters:
r
- the red component is float value from 0.0 to 1.0.g
- the green component is float value from 0.0 to 1.0.b
- the blue component is float value from 0.0 to 1.0.- Throws:
IOException
-
setBrushColor
Sets the color for brush operations. This is the color used when drawing regular text and filling shapes.- Parameters:
r
- the red component is float value from 0.0f to 1.0f.g
- the green component is float value from 0.0f to 1.0f.b
- the blue component is float value from 0.0f to 1.0f.- Throws:
IOException
-
setBrushColor
Sets the color for brush operations.- Parameters:
color
- the color.- Throws:
IOException
-
getBrushColor
public float[] getBrushColor()Returns the brush color.- Returns:
- the brush color.
-
setPenColor
Sets the pen color.- Parameters:
color
- the color. See the Color class for predefined values or define your own using 0x00RRGGBB packed integers.- Throws:
IOException
-
setBrushColor
Sets the brush color.- Parameters:
color
- the color. See the Color class for predefined values or define your own using 0x00RRGGBB packed integers.- Throws:
IOException
-
setDefaultLineWidth
Sets the line width to the default. The default is the finest line width.- Throws:
IOException
-
setLinePattern
The line dash pattern controls the pattern of dashes and gaps used to stroke paths. It is specified by a dash array and a dash phase. The elements of the dash array are positive numbers that specify the lengths of alternating dashes and gaps. The dash phase specifies the distance into the dash pattern at which to start the dash. The elements of both the dash array and the dash phase are expressed in user space units.Examples of line dash patterns: "[Array] Phase" Appearance Description _______________ _________________ ____________________________________ "[] 0" ----------------- Solid line "[3] 0" --- --- --- 3 units on, 3 units off, ... "[2] 1" - -- -- -- -- 1 on, 2 off, 2 on, 2 off, ... "[2 1] 0" -- -- -- -- -- -- 2 on, 1 off, 2 on, 1 off, ... "[3 5] 6" --- --- 2 off, 3 on, 5 off, 3 on, 5 off, ... "[2 3] 11" - -- -- -- 1 on, 3 off, 2 on, 3 off, 2 on, ...
- Parameters:
pattern
- the line dash pattern.- Throws:
IOException
-
setDefaultLinePattern
Sets the default line dash pattern - solid line.- Throws:
IOException
-
setPenWidth
Sets the pen width that will be used to draw lines and splines on this page.- Parameters:
width
- the pen width.- Throws:
IOException
-
setPenWidth
Sets the pen width that will be used to draw lines and splines on this page.- Parameters:
width
- the pen width.- Throws:
IOException
-
setLineCapStyle
Sets the current line cap style.- Parameters:
style
- the cap style of the current line. Supported values: Cap.BUTT, Cap.ROUND and Cap.PROJECTING_SQUARE- Throws:
IOException
-
setLineJoinStyle
Sets the line join style.- Parameters:
style
- the line join style code. Supported values: Join.MITER, Join.ROUND and Join.BEVEL- Throws:
IOException
-
moveTo
Moves the pen to the point with coordinates (x, y) on the page.- Parameters:
x
- the x coordinate of new pen position.y
- the y coordinate of new pen position.- Throws:
IOException
-
moveTo
Moves the pen to the point with coordinates (x, y) on the page.- Parameters:
x
- the x coordinate of new pen position.y
- the y coordinate of new pen position.- Throws:
IOException
-
lineTo
Draws a line from the current pen position to the point with coordinates (x, y), using the current pen width and stroke color. Make sure you call strokePath(), closePath() or fillPath() after the last call to this method.- Throws:
IOException
-
lineTo
Draws a line from the current pen position to the point with coordinates (x, y), using the current pen width and stroke color. Make sure you call strokePath(), closePath() or fillPath() after the last call to this method.- Throws:
IOException
-
strokePath
Draws the path using the current pen color.- Throws:
IOException
-
closePath
Closes the path and draws it using the current pen color.- Throws:
IOException
-
fillPath
Closes and fills the path with the current brush color.- Throws:
IOException
-
drawRect
Draws the outline of the specified rectangle on the page. The left and right edges of the rectangle are at x and x + w. The top and bottom edges are at y and y + h. The rectangle is drawn using the current pen color.- Parameters:
x
- the x coordinate of the rectangle to be drawn.y
- the y coordinate of the rectangle to be drawn.w
- the width of the rectangle to be drawn.h
- the height of the rectangle to be drawn.- Throws:
IOException
-
drawRect
Draws the outline of the specified rectangle on the page. The left and right edges of the rectangle are at x and x + w. The top and bottom edges are at y and y + h. The rectangle is drawn using the current pen color.- Parameters:
x
- the x coordinate of the rectangle to be drawn.y
- the y coordinate of the rectangle to be drawn.w
- the width of the rectangle to be drawn.h
- the height of the rectangle to be drawn.- Throws:
IOException
-
fillRect
Fills the specified rectangle on the page. The left and right edges of the rectangle are at x and x + w. The top and bottom edges are at y and y + h. The rectangle is drawn using the current pen color.- Parameters:
x
- the x coordinate of the rectangle to be drawn.y
- the y coordinate of the rectangle to be drawn.w
- the width of the rectangle to be drawn.h
- the height of the rectangle to be drawn.- Throws:
IOException
-
fillRect
Fills the specified rectangle on the page. The left and right edges of the rectangle are at x and x + w. The top and bottom edges are at y and y + h. The rectangle is drawn using the current pen color.- Parameters:
x
- the x coordinate of the rectangle to be drawn.y
- the y coordinate of the rectangle to be drawn.w
- the width of the rectangle to be drawn.h
- the height of the rectangle to be drawn.- Throws:
IOException
-
drawPath
Draws or fills the specified path using the current pen or brush.- Parameters:
path
- the path.operation
- specifies 'stroke' or 'fill' operation.- Throws:
Exception
-
drawCircle
Draws a circle on the page. The outline of the circle is drawn using the current pen color.- Parameters:
x
- the x coordinate of the center of the circle to be drawn.y
- the y coordinate of the center of the circle to be drawn.r
- the radius of the circle to be drawn.- Throws:
Exception
-
drawCircle
Draws a circle on the page. The outline of the circle is drawn using the current pen color.- Parameters:
x
- the x coordinate of the center of the circle to be drawn.y
- the y coordinate of the center of the circle to be drawn.r
- the radius of the circle to be drawn.- Throws:
Exception
-
drawCircle
Draws the specified circle on the page and fills it with the current brush color.- Parameters:
x
- the x coordinate of the center of the circle to be drawn.y
- the y coordinate of the center of the circle to be drawn.r
- the radius of the circle to be drawn.operation
- must be Operation.STROKE, Operation.CLOSE or Operation.FILL.- Throws:
Exception
-
drawCircle
Draws the specified circle on the page and fills it with the current brush color.- Parameters:
x
- the x coordinate of the center of the circle to be drawn.y
- the y coordinate of the center of the circle to be drawn.r
- the radius of the circle to be drawn.operation
- must be Operation.STROKE, Operation.CLOSE or Operation.FILL.- Throws:
Exception
-
drawEllipse
Draws an ellipse on the page using the current pen color.- Parameters:
x
- the x coordinate of the center of the ellipse to be drawn.y
- the y coordinate of the center of the ellipse to be drawn.r1
- the horizontal radius of the ellipse to be drawn.r2
- the vertical radius of the ellipse to be drawn.- Throws:
Exception
-
drawEllipse
Draws an ellipse on the page using the current pen color.- Parameters:
x
- the x coordinate of the center of the ellipse to be drawn.y
- the y coordinate of the center of the ellipse to be drawn.r1
- the horizontal radius of the ellipse to be drawn.r2
- the vertical radius of the ellipse to be drawn.- Throws:
Exception
-
fillEllipse
Fills an ellipse on the page using the current pen color.- Parameters:
x
- the x coordinate of the center of the ellipse to be drawn.y
- the y coordinate of the center of the ellipse to be drawn.r1
- the horizontal radius of the ellipse to be drawn.r2
- the vertical radius of the ellipse to be drawn.- Throws:
Exception
-
fillEllipse
Fills an ellipse on the page using the current pen color.- Parameters:
x
- the x coordinate of the center of the ellipse to be drawn.y
- the y coordinate of the center of the ellipse to be drawn.r1
- the horizontal radius of the ellipse to be drawn.r2
- the vertical radius of the ellipse to be drawn.- Throws:
Exception
-
drawPoint
Draws a point on the page using the current pen color.- Parameters:
p
- the point.- Throws:
Exception
-
setTextRenderingMode
Sets the text rendering mode.- Parameters:
mode
- the rendering mode.- Throws:
Exception
-
setTextDirection
Sets the text direction.- Parameters:
degrees
- the angle.- Throws:
Exception
-
bezierCurveTo
Draws a bezier curve starting from the current point. Please note: You must call the fillPath, closePath or strokePath method after the last bezierCurveTo call.Author: Pieter Libin, pieter@emweb.be
- Parameters:
p1
- first control pointp2
- second control pointp3
- end point- Throws:
IOException
-
setTextStart
Sets the start of text block. Please see Example_32. This method must have matching call to setTextEnd().- Throws:
IOException
-
setTextLocation
Sets the text location. Please see Example_32.- Parameters:
x
- the x coordinate of new text location.y
- the y coordinate of new text location.- Throws:
IOException
-
setTextBegin
- Throws:
IOException
-
setTextLeading
Sets the text leading. Please see Example_32.- Parameters:
leading
- the leading.- Throws:
IOException
-
setCharSpacing
- Throws:
IOException
-
setWordSpacing
- Throws:
IOException
-
setTextScaling
- Throws:
IOException
-
setTextRise
- Throws:
IOException
-
setTextFont
- Throws:
IOException
-
println
Prints a line of text and moves to the next line. Please see Example_32.- Throws:
IOException
-
print
Prints a line of text. Please see Example_32.- Throws:
IOException
-
println
Move to the next line. Please see Example_32.- Throws:
IOException
-
setTextEnd
Sets the end of text block. Please see Example_32.- Throws:
IOException
-
drawRectRoundCorners
public void drawRectRoundCorners(float x, float y, float w, float h, float r1, float r2, char operation) throws Exception - Throws:
Exception
-
clipPath
Clips the path.- Throws:
IOException
-
clipRect
- Throws:
IOException
-
save
- Throws:
IOException
-
restore
- Throws:
IOException
-
setCropBox
public void setCropBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page CropBox. See page 77 of the PDF32000_2008.pdf specification.- Parameters:
upperLeftX
- the top left X coordinate of the CropBox.upperLeftY
- the top left Y coordinate of the CropBox.lowerRightX
- the bottom right X coordinate of the CropBox.lowerRightY
- the bottom right Y coordinate of the CropBox.
-
setBleedBox
public void setBleedBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page BleedBox. See page 77 of the PDF32000_2008.pdf specification.- Parameters:
upperLeftX
- the top left X coordinate of the BleedBox.upperLeftY
- the top left Y coordinate of the BleedBox.lowerRightX
- the bottom right X coordinate of the BleedBox.lowerRightY
- the bottom right Y coordinate of the BleedBox.
-
setTrimBox
public void setTrimBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page TrimBox. See page 77 of the PDF32000_2008.pdf specification.- Parameters:
upperLeftX
- the top left X coordinate of the TrimBox.upperLeftY
- the top left Y coordinate of the TrimBox.lowerRightX
- the bottom right X coordinate of the TrimBox.lowerRightY
- the bottom right Y coordinate of the TrimBox.
-
setArtBox
public void setArtBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) Sets the page ArtBox. See page 77 of the PDF32000_2008.pdf specification.- Parameters:
upperLeftX
- the top left X coordinate of the ArtBox.upperLeftY
- the top left Y coordinate of the ArtBox.lowerRightX
- the bottom right X coordinate of the ArtBox.lowerRightY
- the bottom right Y coordinate of the ArtBox.
-
append
- Throws:
IOException
-
append
- Throws:
IOException
-
append
- Throws:
IOException
-
append
- Throws:
IOException
-
append
- Throws:
IOException
-
append
Appends the specified array of bytes to the page.- Throws:
IOException
-
drawString
protected void drawString(Font font, String str, float x, float y, Map<String, Integer> colors) throws Exception- Throws:
Exception
-
setStructElementsPageObjNumber
- Throws:
Exception
-
addBMC
- Throws:
Exception
-
addBMC
public void addBMC(String structure, String language, String altDescription, String actualText) throws Exception - Throws:
Exception
-
addEMC
- Throws:
Exception
-
addAnnotation
protected void addAnnotation(net.atthegate.server.service.pdf.Annotation annotation) -
beginTransform
- Throws:
Exception
-
endTransform
- Throws:
Exception
-
drawContents
public void drawContents(byte[] content, float h, float x, float y, float xScale, float yScale) throws Exception - Throws:
Exception
-
drawString
- Throws:
Exception
-
addWatermark
- Throws:
Exception
-
invertYAxis
- Throws:
Exception
-
transform
Transformation matrix. Use save before, restore afterwards! 9 value array like generated by androids Matrix.getValues()- Throws:
IOException
-