Class PDFPage
- java.lang.Object
-
- org.faceless.pdf2.PDFPage
-
- All Implemented Interfaces:
java.lang.Cloneable
,PDFDrawable
public final class PDFPage extends java.lang.Object implements PDFDrawable
Represents a Page in aPDF
document.1. Geometry
By default, the geometry of a PDF page is measured in points (defined in PostScript as 1/72 of an inch), from the bottom-left hand corner of the page. This can be altered by calling the
setUnits()
method, which can be used to set the page to measure in CM, MM, inches and so on, or change the origin (0,0) point from the bottom left of the page to the top left.2. Drawing Shapes
Geometric shapes are drawn using either the simple "draw" methods or the more powerful "path" methods. Whether the shape is filled or just drawn as an outline depends on the
FillColor
andLineColor
of the current style.-
drawLine()
,drawRectangle()
,drawPolygon()
,drawEllipse()
,drawCircle()
,drawCircleArc()
,drawEllipseArc()
,drawRoundedRectangle()
: These methods draw simple shapes onto the page with a single method call.PDFPage page = pdf.newPage(PAGESIZE_A4); PDFStyle linestyle = new PDFStyle(); linestyle.setLineColor(java.awt.Color.red); // Draw a rectangle with two diagonal lines inside it. page.setStyle(linestyle); page.drawRectangle(100,100, 400, 300); // Box page.drawLine(100,100, 400, 300); // Diagonal 1 page.drawLine(100,300, 400, 100); // Diagonal 2
-
pathMove()
,pathLine()
,pathBezier()
,pathArc()
andpathClose()
: These more primitive methods allow greater control over the creation of geometric shapes, by creating a "path" which can then be drawn with thepathPaint()
method.PDFPage page = pdf.newPage(PAGESIZE_A4); PDFStyle linestyle = new PDFStyle(); linestyle.setLineColor(java.awt.Color.red); // Draw the same rectangle with two diagonal lines inside it. page.setStyle(linestyle); page.pathMove(100,100); // Start Box page.pathLine(100,300); page.pathLine(400,300); page.pathLine(400,100); page.pathLine(100,300); // Diagonal 1 page.pathMove(100,100); // Start Diagonal 2 page.pathLine(400,300); page.pathPaint(); // Paint everything since the first pathMove
- A single lines of text can be drawn at a specified location by using the
drawText(String, float, float)
method.PDFPage page = pdf.newPage(PAGESIZE_A4); PDFStyle textstyle = new PDFStyle(); textstyle.setFillColor(java.awt.Color.black); textstyle.setFont(new StandardFont(StandardFont.COURIER), 12); // Draw some text at the specified location page.setStyle(textstyle); page.drawText("This is some text", 100, 100);
- Larger blocks of text can be drawn by calling
beginText()
, followed by one or more calls todrawText(String)
, and closing with a call toendText()
. Until version 1.2 of the library, this method was the only way to draw text over multiple lines, and while it is quite capable (allowing you to mix several styles in a single paragraph), it does not handle wrapping at the end of a page or column well, cannot wrap around images or other blocks and has problems with exact positioning and measurement of text. It's also a bit slower than the next method. Still, we'll demonstrate it here for completeness.PDFPage page = pdf.newPage(PAGESIZE_A4); // 595 x 842 points // Create first style - 12pt black Helvetica PDFStyle style1 = new PDFStyle(); style1.setFillColor(java.awt.Color.black); style1.setFont(new StandardFont(StandardFont.HELVETICA), 12); // Create second style - 12pt black Verdana (TrueType font) PDFStyle style2 = (PDFStyle)style1.clone(); PDFFont ver = new OpenTypeFont(new FileInputStream("verdana.ttf"), 1); style2.setFont(ver, 12); // Draw some text. Use the whole page, less a 100 point margin. page.beginText(100,100, page.getWidth()-100, page.getHeight()-100); page.setStyle(style1); page.drawText("This text is in "); page.setStyle(style2); page.drawText("Verdana.\n"); page.setStyle(style1); page.drawText("And this is Helvetica again."); page.endText(false);
-
The final way to draw text is to use a
LayoutBox
class and thedrawLayoutBox()
method. This is the most powerful way to add text to a page, and has a number of advantages. See theLayoutBox
class API documentation for more details. Here is a quick example that achieves a similar result to the example above.PDFPage page = pdf.newPage(PAGESIZE_A4); // 595 x 842 points // Create first style - 12pt black Helvetica PDFStyle style1 = new PDFStyle(); style1.setFillColor(java.awt.Color.black); style1.setFont(new StandardFont(StandardFont.HELVETICA), 12); // Create second style - 12pt black Verdana (TrueType font) PDFStyle style2 = (PDFStyle)style1.clone(); PDFFont ver = new OpenTypeFont(new FileInputStream("verdana.ttf"), 1); LayoutBox box = new LayoutBox(page.getWidth()-200); box.addText("This text is in ", style1, null); box.addText("Verdana.", style2, null); box.addLineBreak(style2); box.addText("And this is Helvetica again.", style1, null); page.drawLayoutBox(box, 100, page.getHeight()-100);
Bitmap images (represented by the
PDFImage
class) are drawn using thedrawImage()
method.PDFImage img = new PDFImage(new FileInputStream("mypicture.jpg")); page.drawImage(img, 100, 100, 200, 200);
A
PDFCanvas
can be drawn almost exactly the same way, using thedrawCanvas()
method. A canvas can be created from another page, loaded from a file or created from scratch. A typical use of a canvas would be to draw a pattern created elsewhere, or perhaps a copy of an existing page, onto another page.PDFCanvas canvas = new PDFCanvas(template.getPage(0)); newpdf.getPage(0).drawCanvas(0,0,pagewidth, pageheight);
5. Rotate and Save/RestoreAt any point the page can be rotated around a point, using the
rotate()
method. This affects any further graphics operations to the page - drawing lines, text, images and so on. For example, to draw text at a 45° angle, you could do something like this:page.rotate(x, y, 45); page.drawText("Rotated", x, y);
However, due to the vagaries of floating point arithmatic, if you want to rotate the page back to where it was, the results may not be identical. A much better way to do this is to wrap your rotation in a
save()
/restore()
block. These methods save the current page state to a stack and then restore it. It's a very good idea to save the state and restore it before applying a rotation, like so:page.save(); page.rotate(x, y, 45); page.drawText("Rotated", x, y); page.restore();
7. ClippingSimilar to the
drawRectangle
,drawCircle
etc. methods above, theclipRectangle()
,clipRoundedRectangle()
,clipCircle()
,clipEllipse()
andclipPolygon()
methods can be used to set the current clipping area on the page. Any future graphics or text operations will only take place inside that clipping area, which defaults to the entire page. For finer control, a path can be drawn using the path methods demonstrated above, and thepathClip()
method used to set the clipping area.There is no way to enlarge the current clipping area, or to set a new clipping area without reference to the current one. However, as the current clipping area is part of the graphics state, it can (and should) be nested inside calls to
save()
andrestore()
to limit its effect.Here's an example which draws an image on the page, clipped to a circle.
page.save(); // Save the current clipping path - the whole page PDFImage img = new PDFImage(new FileInputStream("mypicture.jpg")); page.clipEllipse(100,100,300,300); page.drawImage(img, 100, 100, 300, 300); page.restore(); // Restore the previous clipping path
8. AnnotationsIn addition to all the methods above, which directly affect the contents of the page, Annotations can be added above the page via the
getAnnotations()
method to provide additional visual effects. This distinction is very important. As annotations are not part of the page, they are not affected by any calls tosetUnits
,rotate
and similar methods, are not copied to a canvas when a new canvas is made using thePDFCanvas(PDFPage)
constructor and so on. Annotations would typically be used to add a popup note, a hyperlink, a stamp or a form-field to a page. For example, here's how to add a hyperlink to a page:AnnotationLink link = new AnnotationLink(); link.setRectangle(100, 100, 200, 200); link.setAction(PDFAction.goToURL("http://bfo.com")); page.getAnnotations().add(link);
-
-
Field Summary
Fields Modifier and Type Field Description static int
ORIGIN_PAGEBOTTOM
Argument tosetUnits(float, int)
to measure the page from the bottomstatic int
ORIGIN_PAGELEFT
Argument tosetUnits(float, int)
to measure the page from the leftstatic int
ORIGIN_PAGERIGHT
Argument tosetUnits(float, int)
to measure the page from the rightstatic int
ORIGIN_PAGETOP
Argument tosetUnits(float, int)
to measure the page from the topstatic float
UNITS_CM
Argument tosetUnits(float, int)
to measure the page in centimeters. 1cm = 28.346457 points.static float
UNITS_INCHES
Argument tosetUnits(float, int)
to measure the page in inches. 1" = 72 pointsstatic float
UNITS_MM
Argument tosetUnits(float, int)
to measure the page in millimeters. 1mm = 2.8346457 points.static float
UNITS_PERCENT
Argument tosetUnits(float, int)
to measure the page in percent.static float
UNITS_PICAS
Argument tosetUnits(float, int)
to measure the page in picas. 1 pica = 12 points.static float
UNITS_POINTS
Argument tosetUnits(float, int)
to measure the page in points (the default).
-
Constructor Summary
Constructors Constructor Description PDFPage(int width, int height)
Create a newPDFPage
object that's not connected to any document.PDFPage(java.lang.String pagesize)
Create a new page of the specified page size that is not connected to any document.PDFPage(PDFPage page)
Create a newPDFPage
object that's a clone of the specified page but is not connected to any document.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to this PDFPage.void
beginTag(java.lang.String tag, java.util.Map<java.lang.String,java.lang.Object> atts)
Open a structural tag on this page.void
beginText(float x1, float y1, float x2, float y2)
Begin a paragraph of text.void
beginTextLink(PDFAction action, PDFStyle linkstyle)
Start a "link" section in the text.void
clipCircle(float x, float y, float radius)
Set the clipping area to a circle centered onx
,y
with a radius ofradius
.void
clipEllipse(float x1, float y1, float x2, float y2)
Set the clipping area to the ellipse inside the specified rectangle.void
clipPolygon(float[] x, float[] y)
Set the clipping area to a polygon.void
clipRectangle(float x1, float y1, float x2, float y2)
Set the clipping area to the rectangle which runs through the two cornersx1,y1
andx2,y2
.void
clipRoundedRectangle(float x1, float y1, float x2, float y2, float radius)
Set the clipping area to a rectangle with rounded corners which runs through the two cornersx1,y1
andx2,y2
.void
clipShape(java.awt.Shape shape)
Clip aShape
protected java.lang.Object
clone()
float
continueText(float x1, float y1, float x2, float y2, PDFPage page)
As for beginText, but continue any text that overflowed from the specified page.java.awt.Graphics2D
createGraphics(PDF pdf)
Create aGraphics2D
object which can be used to write to this page.float
discardText()
Discard the paragraph of text.void
drawCanvas(PDFCanvas canvas, float x1, float y1, float x2, float y2)
Draw aPDFCanvas
at the specified position on the page.void
drawCircle(float x, float y, float radius)
Draw a circle centered onx
,y
with a radius ofradius
.void
drawCircleArc(float x, float y, float radius, float start, float end)
Draw an arc of the circle centered onx,y
with the specified radius.void
drawEllipse(float x1, float y1, float x2, float y2)
Draw an ellipse inside the specified rectangle.void
drawEllipseArc(float x1, float y1, float x2, float y2, float start, float end)
Draw an ellipse arc inside the specified rectangle.void
drawGlyphVector(PDFGlyphVector vector, float x, float y)
Draw aPDFGlyphVector
onto the drawable.void
drawImage(PDFImage image, float x1, float y1, float x2, float y2)
Draw aPDFImage
at the specified position on the pagevoid
drawLayoutBox(LayoutBox box, float x, float y)
Draw aLayoutBox
at the specified position on the pagevoid
drawLine(float x1, float y1, float x2, float y2)
Draw a line fromx1,y1
tox2,y2
.void
drawPolygon(float[] x, float[] y)
Draw a polygon.void
drawRectangle(float x1, float y1, float x2, float y2)
Draw a rectangle through the two cornersx1,y1
andx2,y2
.void
drawRoundedRectangle(float x1, float y1, float x2, float y2, float radius)
Draw a rectangle with rounded corners through the two cornersx1,y1
andx2,y2
.void
drawShape(java.awt.Shape shape)
Draw aShape
If the fill color is specified the Shape will be closed automatically if it isn't already.float
drawText(java.lang.String text)
Draw a paragraph of text in the current style.void
drawText(java.lang.String text, float x, float y)
Draw a line of text at the specified position.void
drawTextLink(java.lang.String text, float x, float y, PDFAction action)
Draw a line of text at a the specified position, and set it to link to the specified action.void
endTag()
Close a structural tag on this page.float
endText(boolean justifylast)
End the paragraph of text.PDFAnnotation[]
endTextLink()
End the "link" section in the text, analogous to the </A> tag in HTML.void
flush()
Flush any operations that have been written to the page.PDFAction
getAction(Event event)
Get the action that's perform when this page is displayed.java.util.List<PDFAnnotation>
getAnnotations()
Return aList
of thePDFAnnotation
objects on this page.java.util.Collection<EmbeddedFile>
getAssociatedFiles()
Return the list of embedded files assocatiated with this PDFAnnotation.float[]
getBox(java.lang.String name)
Return the specified Page Box - see thesetBox
method for a description of Page Boxes.java.awt.color.ColorSpace
getDefaultColorSpace(int components)
Return the ColorSpace used by this page to anchor device-dependent colors to a profile.DocumentPart
getDocumentPart()
Return theDocumentPart
this page belongs to, or null if it doesn't belong to anyint
getHeight()
Return the height of this page in points.java.io.Reader
getMetaData()
Return any XML metadata associated with this object.int
getPageNumber()
Return the page number of this page in it's PDF, or zero if the page is not part of a PDF document.int
getPageOrientation()
Get the current page orientation.PDF
getPDF()
Return the PDF this page is part of, ornull
if it hasn't been attached to a PDF yet.PDFStyle
getStyle()
Return the style used on the pagePDFImage
getThumbnail()
Return the thumbnail image on the page, as set bysetThumbnail(org.faceless.pdf2.PDFImage)
.java.lang.Object
getUserData(java.lang.String key)
Return a property previously set on the PDF with theputUserData()
methodfloat
getUserUnit()
Return the UserUnit, as set bysetUserUnit(float)
int
getWidth()
Return the width of this page in points.XMP
getXMP()
Return an XMP Metadata object representing any XML metadata associated with this objectboolean
pathArc(float width, float height, float start, float end)
Continue the open path in an arc to the specified position.boolean
pathBezier(float cx1, float cy1, float cx2, float cy2, float x, float y)
Continue the open path in a bezier curve to the specified position.void
pathCancel()
Cancel the current pathvoid
pathClip()
Close the path and set the "clipping area" of the page to be the intersection of the current clipping area and the shape defined by this path.void
pathClipAndPaint()
Close and paint the path as described inpathPaint()
, then set the clipping area to the same are as described inpathClip()
void
pathClose()
Close the path by drawing a straight line back to it's beginningboolean
pathLine(float x, float y)
Continue the open path in a straight line to the specified position.void
pathMove(float x, float y)
Start a new path at the specified position.void
pathPaint()
Close and paint the path.boolean
pathShape(java.awt.Shape shape)
Add the path specified by aShape
to the Pagevoid
putLiteral(java.lang.String key, java.lang.String tokens)
Put a literal token sequnce.void
putUserData(java.lang.String key, java.lang.Object value)
Set a custom property on the PDF.void
rawWrite(java.lang.String data)
Write raw PDF commands to the page.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a previously added PropertyChangeListener from this PDFPage.void
restore()
Restore the state that was saved with the last call tosave()
void
rotate(float x, float y, double angle)
Rotate the page.void
save()
Save the state of this page.void
seekEnd()
Seek to the end of the page.void
seekStart()
Seek to the start of the page.void
setAction(Event event, PDFAction action)
Set the action to perform when the specified event occurs.void
setBox(java.lang.String name, float x1, float y1, float x2, float y2)
Set one of the various Page Boxes that control how the page is printed and displayed.void
setDefaultColorSpace(int components, java.awt.color.ColorSpace cs)
Set the ColorSpace to use to anchor device-dependent colors on this page, as described bygetColorSpace(java.lang.String)
.void
setMeasurementUnits(float x1, float y1, float x2, float y2, java.lang.String scale)
Set the natural scale for measurements in the specified area of the page.void
setMetaData(java.lang.String xmldata)
Set the XML metadata associated with this object.void
setPageOrientation(int degrees)
Set the orientation of the page.void
setStyle(PDFStyle style)
Set the style to use for future drawing operations on this pagevoid
setThumbnail(PDFImage image)
Set the embedded page thumbnail.void
setTransition(java.lang.String style, float displaytime, float transitiontime)
Set a transition from this page to the next page, to allow the pages to be displayed as part of a presentation.void
setUnits(float units, int origin)
Set the coordinates of the current page.void
setUserUnit(float unit)
Set the "User Unit" on the PDF.java.lang.String
toString()
void
transform(double a, double b, double c, double d, double e, double f)
Concatenate the specified AffineTransform to the page's current transform.void
transform(java.awt.geom.AffineTransform transform)
Concatenate the specified AffineTransform to the page's current transform.
-
-
-
Field Detail
-
UNITS_INCHES
public static final float UNITS_INCHES
Argument tosetUnits(float, int)
to measure the page in inches. 1" = 72 points- See Also:
- Constant Field Values
-
UNITS_CM
public static final float UNITS_CM
Argument tosetUnits(float, int)
to measure the page in centimeters. 1cm = 28.346457 points.- See Also:
- Constant Field Values
-
UNITS_MM
public static final float UNITS_MM
Argument tosetUnits(float, int)
to measure the page in millimeters. 1mm = 2.8346457 points.- See Also:
- Constant Field Values
-
UNITS_PICAS
public static final float UNITS_PICAS
Argument tosetUnits(float, int)
to measure the page in picas. 1 pica = 12 points.- See Also:
- Constant Field Values
-
UNITS_PERCENT
public static final float UNITS_PERCENT
Argument tosetUnits(float, int)
to measure the page in percent. Unlike the other measurements, this can result in changes to the aspect ratio. (10% of the page width is usually less than 10% of the page height).- See Also:
- Constant Field Values
-
UNITS_POINTS
public static final float UNITS_POINTS
Argument tosetUnits(float, int)
to measure the page in points (the default). One point is 1/72nd of an inch.- See Also:
- Constant Field Values
-
ORIGIN_PAGEBOTTOM
public static final int ORIGIN_PAGEBOTTOM
Argument tosetUnits(float, int)
to measure the page from the bottom- See Also:
- Constant Field Values
-
ORIGIN_PAGETOP
public static final int ORIGIN_PAGETOP
Argument tosetUnits(float, int)
to measure the page from the top- See Also:
- Constant Field Values
-
ORIGIN_PAGELEFT
public static final int ORIGIN_PAGELEFT
Argument tosetUnits(float, int)
to measure the page from the left- See Also:
- Constant Field Values
-
ORIGIN_PAGERIGHT
public static final int ORIGIN_PAGERIGHT
Argument tosetUnits(float, int)
to measure the page from the right- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PDFPage
public PDFPage(int width, int height)
Create a new
PDFPage
object that's not connected to any document. In most cases it will be more convenient to call thePDF.newPage(int,int)
method, which creates a new page and adds it to aPDF
.The parameters are integers for API compatibility only. If required you can create pages sized to a fraction of a point with the
PDFPage(String)
constructor.- Since:
- 2.0
-
PDFPage
public PDFPage(java.lang.String pagesize)
Create a new page of the specified page size that is not connected to any document. In most cases it will be more convenient to call
PDF.newPage(String)
, which create the page and links it to the PDF.The size is specified as a string of the form "WxHU", where W is the width of the page, H is the height of the page, and U is an optional units specifier - it may be "mm", "cm" or "in", and if it's not specified it's assumed to be points. The resulting page size is rounded to the nearest integer unless the units are specified as points (eg.
595.5x842
- fractional sizes added in 2.2.3)For convenience we've defined several standard sizes that you can pass in, like
PDF.PAGESIZE_A4
,PDF.PAGESIZE_A4_LANDSCAPE
,PDF.PAGESIZE_LETTER
,PDF.PAGESIZE_LETTER_LANDSCAPE
and so on.Since 2.2.3 you can also pass in a String containing the common name of the paper size, optionally with a "-landscape" suffix, eg "A4", "Letter", "A2-landscape", "DL" and so on. All ISO sizes and most US and JIS paper (and some envelope) sizes are recognised.
Example values include "210x297mm", "595x842" or "A4", which would both produce an A4 page, and "8.5x11in", "612x792" or "Letter", which would both produce a US Letter page.
- Parameters:
pagesize
- the size of the page to create- Throws:
java.lang.IllegalArgumentException
- if the specified page size cannot be parsed
-
PDFPage
public PDFPage(PDFPage page)
Create a newPDFPage
object that's a clone of the specified page but is not connected to any document. In most cases it will be more convenient to call thePDF.newPage(PDFPage)
method, which creates a new page and adds it to aPDF
.- Since:
- 2.0
-
-
Method Detail
-
getUserUnit
public float getUserUnit()
Return the UserUnit, as set bysetUserUnit(float)
- Since:
- 2.22
-
setUserUnit
public void setUserUnit(float unit)
Set the "User Unit" on the PDF. This is a new feature added in PDF 1.6 / Acrobat 5.0 to get around the self-imposed limitation in Acrobat on maximum page size, which is 14400x14400 units. By default a unit is a point, but this method can be used to change this - for example,
setUserUnit(10)
means a page size of 72x72 points is actually treated as 720x720 points by Acrobat.This scaling also applies to any PDFCanvas object drawn to the page, and any annotation or hyperlink coordinates. Moving an annotation from a page with UserUnits set to 2 to another page with UserUnits set to the default value of 1, will effectively halve the size of the annotation.
This method is very similar to the
setUnits(float, int)
method, except that the user scale is stored with the PDF.- Since:
- 2.22
-
setPageOrientation
public void setPageOrientation(int degrees)
Set the orientation of the page. This method can be used to rotate the page clockwise or counter-clockwise by 90 degrees. Typically the value passed in will begetPageOrientation()
+/- 90
, to rotate the page 90 degrees clockwise or anti-clockwise.- Parameters:
degrees
- one of 0, 90, 180 or 270- Since:
- 2.8.3
-
getPageOrientation
public int getPageOrientation()
Get the current page orientation. Although this value can give some indication of whether the page is portrait, landscape or reverse-landscape, it's not the only way to determine if a page is in that position. Typically the value for this method is used as a base for the parameter tosetPageOrientation(int)
.- Returns:
- the page orientation - 0, 90, 180 or 270
- Since:
- 2.8.3
-
getPDF
public PDF getPDF()
Return the PDF this page is part of, ornull
if it hasn't been attached to a PDF yet.- Since:
- 2.8
-
flush
public void flush()
Flush any operations that have been written to the page. Pages must be flushed before they can be cloned (by calling the
PDFCanvas(PDFPage)
orPDFPage(PDFPage)
constructors).Pages are considered "flushed" when they are loaded, and only require flushing after an action is performed on its contents, such as calling any of the draw... methods. Adding or removing annotations is not considered to alter the page contents.
After a page has been flushed, it can still be written to without any performance penalty (although calling flush too often will result in larger files, so don't overdo it).
It is a good idea to flush a PDFPage after you've finished modifying it, as the library can manage it more efficiently if it knows you're not expecting to write to it again. In particular, a flushed page may be temporarily written to disk by a
Cache
to free up memory.
-
seekStart
public void seekStart()
Seek to the start of the page. Any items drawn after this call will be drawn before any content already existing on the page, so appearing under the current content.
Note that if the document clears the page before writing, it will overwrite any content written after a seekStart
- Since:
- 1.1.12
-
seekEnd
public void seekEnd()
Seek to the end of the page. Any items drawn after this call will be drawn after any content already existing on the page, so appearing on top of the current content. This is the default position.
- Since:
- 1.1.12
-
setBox
public void setBox(java.lang.String name, float x1, float y1, float x2, float y2)
Set one of the various Page Boxes that control how the page is printed and displayed. The "name" parameter specifies the box, and may be one of "Media", "Crop", "Art", "Bleed" or "Trim". The MediaBox relates to the size of the physical page, and is set in the PDFPage constructor. Consequently you really don't want to set this unless you know exactly what you're doing. The other boxes can be set and reset as many times as required. To remove a previously defined box, set all four values to 0.
Note that like
getBox(java.lang.String)
, box coordinates are relative to the MediaBox (so, for example, when setting the MediaBox then the CropBox, the CropBox should be relative to the new MediaBox rather than the original).- Parameters:
name
- the name of the page box to setx1
- the left-most X co-ordinate of the boxy1
- the bottom-most Y co-ordinate of the boxx2
- the right-most X co-ordinate of the boxy2
- the top-most Y co-ordinate of the box- Since:
- 2.0.7
-
getBox
public float[] getBox(java.lang.String name)
Return the specified Page Box - see the
setBox
method for a description of Page Boxes. If the requested box isn't specified by the page object, this method returns null. Note that since 2.7.3, values are always relative to the MediaBox, which is always anchored at (0,0). The raw box values can be retrieved by prefixing the argument with "Raw", eg "RawMediaBox".Since 2.8 this method accepts "ViewBox" or "PrintBox" as arguments as well. The method will then return the appropriate box for viewing or printing the PDF, which is typically the CropBox if specified or the MediaBox if not - although this can be changed with the
view.area
andprint.area
settings inPDF.setOption()
.- Parameters:
name
- the name of the page box to return.- Returns:
- an array of floats [x1,y1,x2,y2] describing the corners of the requested page box, or
null
if no such box is defined - Since:
- 2.0.7
-
getPageNumber
public int getPageNumber()
Return the page number of this page in it's PDF, or zero if the page is not part of a PDF document. Note the page number starts at one, which is not so useful. Given all this method does internally is callpdf.getPages().indexOf(page) + 1
you might consider doing that instead.- Returns:
- the page number of this page, from 1 to
PDF.getNumberOfPages()
-
setUnits
public void setUnits(float units, int origin)
Set the coordinates of the current page. When a new page is created it's measured in points from the bottom-left of the page. This can be changed as many times as necessary by calling this method.- Parameters:
units
- the units to measure it in. Can beUNITS_POINTS
(the default),UNITS_INCHES
,UNITS_CM
,UNITS_MM
,UNITS_PICAS
orUNITS_PERCENT
origin
- which corner of the page is nearest to (0,0). A logical-or ofORIGIN_PAGETOP
,ORIGIN_PAGELEFT
,ORIGIN_PAGERIGHT
andORIGIN_PAGEBOTTOM
- Since:
- 2.0 - this method replaces the
setCanvas
method in versions prior to 2.0 - See Also:
setUserUnit(float)
-
getDefaultColorSpace
public java.awt.color.ColorSpace getDefaultColorSpace(int components)
Return the ColorSpace used by this page to anchor device-dependent colors to a profile. For example, the ColorSpace returned by
getDefaultColorSpace(3)
is used by all "Device RGB" colors on the page, effectively turning them into calibrated colors.The PDF API automatically sets a calibrated sRGB ColorSpace as the ColorSpace for all DeviceRGB content on the page. Unlike the use of "Output Intents" on the
OutputProfile
class, multiple ColorSpaces can be set, one each for Gray, RGB, and CMYK. This is a cheap way to convert pages containing both DeviceRGB and DeviceCMYK to using calibrated colors.- Specified by:
getDefaultColorSpace
in interfacePDFDrawable
- Parameters:
components
- identifies the Default ColorSpace we're requesting - valid values are 1 for Gray, 3 for RGB or 4 for CMYK.- Returns:
- the Default ColorSpace requested, or null if none is set.
- Since:
- 2.25
-
setDefaultColorSpace
public void setDefaultColorSpace(int components, java.awt.color.ColorSpace cs)
Set the ColorSpace to use to anchor device-dependent colors on this page, as described bygetColorSpace(java.lang.String)
.- Specified by:
setDefaultColorSpace
in interfacePDFDrawable
- Parameters:
components
- identifies the Default ColorSpace to set - valid values are 1 for Gray, 3 for RGB or 4 for CMYK.cs
- the ColorSpace to set, which must be either null (to delete the existing value) or a ColorSpace of a type that matches the "components" parameter.
-
setMetaData
public void setMetaData(java.lang.String xmldata)
Set the XML metadata associated with this object. Since 2.26 this method callsgetXMP().read(new StringReader(xmldata == null ? "" : xmldata))
. We strongly recommend using thegetXMP()
method and modifying the XMP directly rather than using this method.- Specified by:
setMetaData
in interfacePDFDrawable
- Parameters:
xmldata
- the XML data to embed into the document, or null to clear any existing metadata. No validation is performed on this input.- Since:
- 1.1.12
- See Also:
getXMP()
-
getMetaData
public java.io.Reader getMetaData() throws java.io.IOException
Return any XML metadata associated with this object.
Since 2.26 this simply returns
getXMP().isEmpty() ? null : new StringReader(getXMP().toString())
. It is strongly recommended that any code migrates to using thegetXMP()
method.Since 2.24.3, the returned type is guaranteed to hava a
toString()
method that will return the Metadata as a String.- Returns:
- a
Reader
containing the source of the XML or null if no metadata is available. - Throws:
java.io.IOException
- if the metadata can't be extracted- Since:
- 1.1.12
-
getXMP
public XMP getXMP()
Return an XMP Metadata object representing any XML metadata associated with this object- Returns:
- the XMP, which may be empty or invalid but will never be null
- Since:
- 2.26
-
setAction
public void setAction(Event event, PDFAction action)
Set the action to perform when the specified event occurs. Events that occur on a page are limited to open and close, which are run everytime the page is displayed on screen.
- Parameters:
event
- one ofEvent.OPEN
orEvent.CLOSE
.action
- the action to run each time this page is displayed, ornull
to clear the action- Since:
- 2.0
- See Also:
getAction(org.faceless.pdf2.Event)
,PDF.setAction(org.faceless.pdf2.Event, org.faceless.pdf2.PDFAction)
,AnnotationLink.setAction(org.faceless.pdf2.PDFAction)
,FormElement.setAction(org.faceless.pdf2.Event, org.faceless.pdf2.PDFAction)
-
getAction
public PDFAction getAction(Event event)
Get the action that's perform when this page is displayed. This is the value set by the
setAction(org.faceless.pdf2.Event, org.faceless.pdf2.PDFAction)
method.- Returns:
- the action performed whenever the specified event occurs, or null if no action is performed for this event.
- Since:
- 2.0
- See Also:
setAction(org.faceless.pdf2.Event, org.faceless.pdf2.PDFAction)
,PDF.getAction(org.faceless.pdf2.Event)
,AnnotationLink.getAction()
,FormElement.getAction(org.faceless.pdf2.Event)
-
rawWrite
public void rawWrite(java.lang.String data)
Write raw PDF commands to the page. This is for advanced users only, but does allow those intimately familiar with the PDF specification to perform some of the more esoteric actions that aren't directly supported by the PDF library. Using this method it is easy to create invalid PDF documents, so use with caution.- Specified by:
rawWrite
in interfacePDFDrawable
- Parameters:
data
- the PDF operations to write to the stream, for instance "/Perceptual ri" to set the RenderingIntent. Line breaks will be added before and after the specified string.- Since:
- 2.1.2
-
getWidth
public int getWidth()
Return the width of this page in points. For API compatibility reasons only these are rounded to the nearest point, although it is possible to have pages sized to a fraction of a point. If more accuracy is needed you can get the exact page dimensions by calling thegetBox(java.lang.String)
method to get theMediaBox
.- Since:
- 1.0
-
getHeight
public int getHeight()
Return the height of this page in points. For API compatibility reasons only these are rounded to the nearest point, although it is possible to have pages sized to a fraction of a point. If more accuracy is needed you can get the exact page dimensions by calling thegetBox(java.lang.String)
method to get theMediaBox
.- Since:
- 1.0
-
setStyle
public void setStyle(PDFStyle style)
Set the style to use for future drawing operations on this page- Specified by:
setStyle
in interfacePDFDrawable
- Since:
- 1.0
-
getStyle
public PDFStyle getStyle()
Return the style used on the page- Since:
- 1.0
-
drawLine
public void drawLine(float x1, float y1, float x2, float y2)
Draw a line fromx1,y1
tox2,y2
.- Specified by:
drawLine
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the start of the liney1
- the Y co-ordinate of the start of the linex2
- the X co-ordinate of the end of the liney2
- the Y co-ordinate of the end of the line- Since:
- 1.0
-
drawRectangle
public void drawRectangle(float x1, float y1, float x2, float y2)
Draw a rectangle through the two corners
x1,y1
andx2,y2
. Whether the rectangle is drawn as an outline or filled depends on theLineColor
andFillColor
of the current style (see thepathPaint()
method for more information).- Specified by:
drawRectangle
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectangle- Since:
- 1.0
-
drawRoundedRectangle
public void drawRoundedRectangle(float x1, float y1, float x2, float y2, float radius)
Draw a rectangle with rounded corners through the two corners
x1,y1
andx2,y2
. Whether the rectangle is drawn as an outline or filled depends on theLineColor
andFillColor
of the current style (see thepathPaint()
method for more information).- Specified by:
drawRoundedRectangle
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectangleradius
- The radius of the circle that is used to round the corners. A value of zero give identical results todrawRectangle(float, float, float, float)
- Since:
- 1.1
-
drawPolygon
public void drawPolygon(float[] x, float[] y)
Draw a polygon. The X and Y co-ordinates of the vertices are in the supplied arrays. Whether the polygon is drawn as an outline or filled depends on the
LineColor
andFillColor
of the current style (see thepathPaint()
method for more information).If the fill color is specified the polygon will be closed automatically if it isn't already.
- Specified by:
drawPolygon
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinates of the verticesy
- the Y co-ordinates of the vertices- Since:
- 1.0
-
drawCircle
public void drawCircle(float x, float y, float radius)
Draw a circle centered onx
,y
with a radius ofradius
. A more convenient way to draw circles thandrawEllipse
- Specified by:
drawCircle
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinate of the center of the circley
- the Y co-ordinate of the center of the circleradius
- the radius of the circle- Since:
- 1.1
-
drawEllipse
public void drawEllipse(float x1, float y1, float x2, float y2)
Draw an ellipse inside the specified rectangle. The top and sides of the ellipse will touch the edges of the rectangle drawn between
x1,y1
andx2,y2
.Whether the ellipse is drawn as an outline or filled depends on the
LineColor
andFillColor
of the current style (see thepathPaint()
method for more information).- Specified by:
drawEllipse
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectangle- Since:
- 1.0
-
drawEllipseArc
public void drawEllipseArc(float x1, float y1, float x2, float y2, float start, float end)
Draw an ellipse arc inside the specified rectangle. The same as
drawEllipse
, but allows you to specify a start and end angle. If a FillColor is specified, the arc will be closed with a straight line.- Specified by:
drawEllipseArc
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectanglestart
- the start angle of the arc, in degrees clockwise from 12 o'clockend
- the end angle of the arc, in degrees clockwise from 12 o'clock- Since:
- 1.1
-
drawCircleArc
public void drawCircleArc(float x, float y, float radius, float start, float end)
Draw an arc of the circle centered onx,y
with the specified radius. A more convenient way to draw circular arcs thandrawEllipseArc
If a FillColor is specified, the arc will be closed with a straight line.- Specified by:
drawCircleArc
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinate of the center of the circley
- the Y co-ordinate of the center of the circleradius
- the radius of the circlestart
- the start angle of the arc, in degrees clockwise from 12 o'clockend
- the end angle of the arc, in degrees clockwise from 12 o'clock- Since:
- 1.1
-
drawShape
public void drawShape(java.awt.Shape shape)
Draw aShape
If the fill color is specified the Shape will be closed automatically if it isn't already.- Specified by:
drawShape
in interfacePDFDrawable
- Since:
- 2.16
-
clipShape
public void clipShape(java.awt.Shape shape)
Clip aShape
- Specified by:
clipShape
in interfacePDFDrawable
- Since:
- 2.16
-
pathShape
public boolean pathShape(java.awt.Shape shape)
Add the path specified by aShape
to the Page- Specified by:
pathShape
in interfacePDFDrawable
- Parameters:
shape
- the shape- Returns:
- true if any sections were drawn on the path
- Since:
- 2.16
-
pathMove
public void pathMove(float x, float y)
Start a new path at the specified position. If a path has already been started, move the cursor without drawing a line.- Specified by:
pathMove
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinate to move toy
- the Y co-ordinate to move to- Since:
- 1.0
-
pathLine
public boolean pathLine(float x, float y)
Continue the open path in a straight line to the specified position.- Specified by:
pathLine
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinate to move toy
- the Y co-ordinate to move to- Returns:
- true if any sections were drawn in the path
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
- Since:
- 1.0
-
pathBezier
public boolean pathBezier(float cx1, float cy1, float cx2, float cy2, float x, float y)
Continue the open path in a bezier curve to the specified position.- Specified by:
pathBezier
in interfacePDFDrawable
- Parameters:
cx1
- the X co-ordinate of the first control point for the curvecy1
- the Y co-ordinate of the first control point for the curvecx2
- the X co-ordinate of the second control point for the curvecy2
- the Y co-ordinate of the second control point for the curvex
- the X co-ordinate to move toy
- the Y co-ordinate to move to- Returns:
- true if any sections were drawn in the path
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
- Since:
- 1.0
-
pathArc
public boolean pathArc(float width, float height, float start, float end)
Continue the open path in an arc to the specified position.- Specified by:
pathArc
in interfacePDFDrawable
- Parameters:
width
- the width of the ellipse to take the arc fromheight
- the height of the ellipse to take the arc fromstart
- the start angle of the arc, in degrees clockwise from 12 o'clockend
- the end angle of the arc, in degrees clockwise from 12 o'clock- Returns:
- true if any sections were drawn in the path
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
- Since:
- 1.1
-
pathClose
public void pathClose()
Close the path by drawing a straight line back to it's beginning- Specified by:
pathClose
in interfacePDFDrawable
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
- Since:
- 1.0
-
pathCancel
public void pathCancel()
Cancel the current path- Specified by:
pathCancel
in interfacePDFDrawable
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
- Since:
- 1.0
-
pathClip
public void pathClip()
Close the path and set the "clipping area" of the page to be the intersection of the current clipping area and the shape defined by this path. Any future graphics or text operations on the page are only applied within this area.
There is no way to enlarge the current clipping area, or to set a new clipping area without reference to the current one. However, as the current clipping area is part of the graphics state, it can and should be nested inside calls to
save()
andrestore()
to limit its effect.- Specified by:
pathClip
in interfacePDFDrawable
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
- Since:
- 1.1.5
-
pathPaint
public void pathPaint()
Close and paint the path. What this actually does depends on the currently appliedPDFStyle
- If the style has a LineColor specified but no FillColor, "stroke" the path by drawing it as an outline in the current line color
- If the style has a FillColor specified but no LineColor, call
pathClose()
and "fill" the path with the current fill color - If the style has both a FillColor and a LineColor, call
pathClose()
, "fill" the path with the current fill color then "stroke" the path with the current line color.
- Specified by:
pathPaint
in interfacePDFDrawable
- Throws:
java.lang.IllegalStateException
- if a path hasn't been started withpathMove(float, float)
, or if neither a fill nor line color has been specified.- Since:
- 1.0
-
pathClipAndPaint
public void pathClipAndPaint()
Close and paint the path as described inpathPaint()
, then set the clipping area to the same are as described inpathClip()
- Specified by:
pathClipAndPaint
in interfacePDFDrawable
- Since:
- 1.1.10
-
clipRoundedRectangle
public void clipRoundedRectangle(float x1, float y1, float x2, float y2, float radius)
Set the clipping area to a rectangle with rounded corners which runs through the two corners
x1,y1
andx2,y2
.- Specified by:
clipRoundedRectangle
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectangleradius
- The radius of the circle that is used to round the corners. A value of zero give identical results todrawRectangle(float, float, float, float)
- Since:
- 1.1.5
-
clipPolygon
public void clipPolygon(float[] x, float[] y)
Set the clipping area to a polygon. The X and Y co-ordinates of the vertices are in the supplied arrays.
- Specified by:
clipPolygon
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinates of the verticesy
- the Y co-ordinates of the vertices- Since:
- 1.1.5
-
clipRectangle
public void clipRectangle(float x1, float y1, float x2, float y2)
Set the clipping area to the rectangle which runs through the two corners
x1,y1
andx2,y2
.- Specified by:
clipRectangle
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectangle- Since:
- 1.1.5
-
clipEllipse
public void clipEllipse(float x1, float y1, float x2, float y2)
Set the clipping area to the ellipse inside the specified rectangle. The top and sides of the ellipse will touch the edges of the rectangle drawn between
x1,y1
andx2,y2
.- Specified by:
clipEllipse
in interfacePDFDrawable
- Parameters:
x1
- the X co-ordinate of the first corner of the rectangley1
- the Y co-ordinate of the first corner of the rectanglex2
- the X co-ordinate of the second corner of the rectangley2
- the Y co-ordinate of the second corner of the rectangle- Since:
- 1.1.5
-
clipCircle
public void clipCircle(float x, float y, float radius)
Set the clipping area to a circle centered onx
,y
with a radius ofradius
.- Specified by:
clipCircle
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinate of the center of the circley
- the Y co-ordinate of the center of the circleradius
- the radius of the circle- Since:
- 1.1.5
-
drawLayoutBox
public void drawLayoutBox(LayoutBox box, float x, float y)
Draw aLayoutBox
at the specified position on the page- Specified by:
drawLayoutBox
in interfacePDFDrawable
- Parameters:
box
- the LayoutBox to drawx
- the X co-ordinate of the left hand side of the boxy
- the Y co-ordinate of the top side of the box- Since:
- 1.2
-
drawGlyphVector
public void drawGlyphVector(PDFGlyphVector vector, float x, float y)
Description copied from interface:PDFDrawable
Draw aPDFGlyphVector
onto the drawable. See that class for an example of how to use this method.- Specified by:
drawGlyphVector
in interfacePDFDrawable
- Parameters:
vector
- the PDFGlyphVector to drawx
- the X co-ordinate to position the left edge of the PDFGlyphVectory
- the Y co-ordinate to position the baseline of the PDFGlyphVector- See Also:
PDFGlyphVector
,PDFStyle.createGlyphVector(java.lang.String, java.util.Locale)
-
drawImage
public void drawImage(PDFImage image, float x1, float y1, float x2, float y2)
Draw aPDFImage
at the specified position on the page- Specified by:
drawImage
in interfacePDFDrawable
- Parameters:
image
- the image to drawx1
- the X co-ordinate of the left hand side of the imagey1
- the Y co-ordinate of the bottom side of the imagex2
- the X co-ordinate of the right hand side of the imagey2
- the Y co-ordinate of the top side of the image- Since:
- 1.0
-
drawCanvas
public void drawCanvas(PDFCanvas canvas, float x1, float y1, float x2, float y2)
Draw aPDFCanvas
at the specified position on the page.- Specified by:
drawCanvas
in interfacePDFDrawable
- Parameters:
canvas
- the canvas to drawx1
- the X co-ordinate of the left hand side of the imagey1
- the Y co-ordinate of the bottom side of the imagex2
- the X co-ordinate of the right hand side of the imagey2
- the Y co-ordinate of the top side of the image- Since:
- 2.0
-
save
public void save()
Save the state of this page. This takes a snapshot of the currently applied style, position, clipping area and any rotation/translation/scaling that has been applied, which can be later restored with a call to
restore()
.Calls to
save
can be nested, but note that for most PDF viewers it is an error to save the page state but not restore it.- Specified by:
save
in interfacePDFDrawable
- Throws:
java.lang.IllegalStateException
- if a save is performed with an open path or if saves are nested more than 28 deep.- Since:
- 1.0
-
restore
public void restore()
Restore the state that was saved with the last call tosave()
- Specified by:
restore
in interfacePDFDrawable
- Throws:
java.lang.IllegalStateException
- if there is no previously saved state- Since:
- 1.0
-
rotate
public void rotate(float x, float y, double angle)
Rotate the page. All future actions, like drawing lines or text, will be rotated around the specified point by the specified angle.
- Specified by:
rotate
in interfacePDFDrawable
- Parameters:
x
- the X co-ordinate to rotate the page aroundy
- the Y co-ordinate to rotate the page aroundangle
- The number of degrees clockwise to rotate the page.
-
transform
public void transform(java.awt.geom.AffineTransform transform)
Concatenate the specified AffineTransform to the page's current transform. All future actions, like drawing lines or text, will transformed with this matrix. Note that the results for this operation will be incorrect if thesetUnits()
method has been called withORIGIN_PAGEBOTTOM
orORIGIN_PAGERIGHT
- Specified by:
transform
in interfacePDFDrawable
- Since:
- 2.16.1
-
transform
public void transform(double a, double b, double c, double d, double e, double f)
Concatenate the specified AffineTransform to the page's current transform. All future actions, like drawing lines or text, will transformed with this matrix. The six arguments are the same 6 arguments passed in to theAffineTransform
constructor, in the same same order.
Note that the results for this operation will be incorrect if thesetUnits()
method has been called withORIGIN_PAGEBOTTOM
orORIGIN_PAGERIGHT
- Specified by:
transform
in interfacePDFDrawable
- Since:
- 2.16.1
-
getAnnotations
public java.util.List<PDFAnnotation> getAnnotations()
Return aList
of thePDFAnnotation
objects on this page. The list may be manipulated using the standard List methods such asList.add(E)
,List.remove(java.lang.Object)
and so on. If the page has no annotations an empty list is returned.- Since:
- 2.0 (although this method existed in prior versions, it returned an Array)
-
setTransition
public void setTransition(java.lang.String style, float displaytime, float transitiontime)
Set a transition from this page to the next page, to allow the pages to be displayed as part of a presentation. Valid values forstyle
are:None No transition is used (the default) Replace The current page is replaced with the new page. transitiontime
is ignoredSplitHorizOut Two lines sweep horizontally across the screen outward from the center of the page SplitHorizIn Two lines sweep horizontally across the screen inwards from the edge of the page SplitVertOut Two lines sweep vertically across the screen outward from the center of the page SplitVertIn Two lines sweep vertically across the screen inwards from the edge of the page BlindsHoriz Multiple lines sweep down across the page BlindsVert Multiple lines sweep left-to-right across the page BoxIn A box sweeps inwards from the edge of the page BoxOut A box sweeps outwards from the center of the page WipeLeftToRight A single line sweeps across the page from left to right WipeRightToLeft A single line sweeps across the page from right to left WipeTopToBottom A single line sweeps across the page from top to bottom WipeBottomToTop A single line sweeps across the page from bottom to top Dissolve The old page dissolves gradually to reveal the new one GlitterLeftToRight The old page dissolves in a band running from left to right across the page GlitterTopToBottom The old page dissolves in a band running from top to bottom across the page GlitterDiagonal The old page dissolves in a band running from top-left to bottom-right across the page - Parameters:
style
- the transition style as defined abovedisplaytime
- the amount of time in seconds to display the page before automatically moving to the next page, or 0 for manual page transitions onlytransitiontime
- the amount of time to take over the transition, in seconds- Since:
- 2.0
-
drawText
public void drawText(java.lang.String text, float x, float y)
Draw a line of text at the specified position. A simple way to draw a single line of text. The co-ordinates specify the position of the baseline of the first character - for other positions (e.g. to align the top of the text), adjust the co-ordinates by the return value from
PDFStyle.getTextTop(java.lang.String)
and friends.- Parameters:
text
- the line of text to drawx
- the X co-ordinate to draw the text aty
- the Y co-ordinate to draw the text at- Since:
- 1.0
-
drawTextLink
public void drawTextLink(java.lang.String text, float x, float y, PDFAction action)
Draw a line of text at a the specified position, and set it to link to the specified action. A shorthand combination of
drawText
andbeginTextLink
.Note that this method will not work as advertised if the position of the text has been modified via the
rotate(float, float, double)
method. This is a shortcoming inherent in the PDF document specification- Parameters:
text
- the line of text to drawx
- the X co-ordinate to draw the text aty
- the Y co-ordinate to draw the text ataction
- the action to perform when the text is clicked on- Since:
- 1.1
-
beginText
public void beginText(float x1, float y1, float x2, float y2)
Begin a paragraph of text. The parameters specify the rectangle measured in the current canvas units that will fully contain the text. Left-to-right text will wrap when it reaches the right margin and continue being rendered until the bottom margin is reached, after which the text will not be rendered and all calls to
drawText
will return -1. This "overflowed" text can be rendered in a new block by callingcontinueText
Note: Although suitable for layout of simple text paragraphs, the
beginText
/drawText
/continueText
methods are not suitable for complicated text layout involving either precise measurement, such as is required when a paragraph is required to wrap at the end of a section or page. In this situation aLayoutBox
should be used instead.- Parameters:
x1
- the X co-ordinate of the first corner of the text rectangle.y1
- the Y co-ordinate of the first corner of the text rectangle.x2
- the X co-ordinate of the second corner of the text rectangle.y2
- the Y co-ordinate of the second corner of the text rectangle.- Throws:
java.lang.IllegalStateException
- if beginText has already been called (beginText-endText
pairs can't be nested).- See Also:
LayoutBox
-
continueText
public float continueText(float x1, float y1, float x2, float y2, PDFPage page)
As for beginText, but continue any text that overflowed from the specified page. This method is a legacy method kept here for the large install base of 1.0 and 1.1 users. We do not recommend it for new development. If your text is going to be wrapping from one rectangle to another, we strongly recommend you use the
LayoutBox
class.- Parameters:
x1
- the X co-ordinate of the first corner of the text rectangley1
- the Y co-ordinate of the first corner of the text rectanglex2
- the X co-ordinate of the second corner of the text rectangley2
- the Y co-ordinate of the second corner of the text rectanglepage
- the page to take the overflowed text from- See Also:
LayoutBox
-
endText
public float endText(boolean justifylast)
End the paragraph of text.- Parameters:
justifylast
- if the current text style is justified, whether to justify the last line of text. If the current style is not justified, this has no effect.- Returns:
- the number of points that needed to be rendered to clear the buffer
- Throws:
java.lang.IllegalStateException
- if beginText wasn't called first- See Also:
LayoutBox
-
discardText
public float discardText()
Discard the paragraph of text. This method is identical toendText
in every way, except no text is actually rendered. Prior to theLayoutBox
class, this was the only way to determine the height of a block of text without displaying it. It's nowhere near as efficient, and it's use for this purpose is strongly discouraged.- Returns:
- the number of points that would have been rendered to clear the buffer
- Since:
- 1.0.1
- See Also:
LayoutBox
-
drawText
public float drawText(java.lang.String text)
Draw a paragraph of text in the current style. The text is automatically wrapped at the edge of the box specified in the call to
beginText
, and is aligned according to the alignment of the current style.If any characters in the string aren't available in the current font, they are ignored and a warning message is printed to
System.err
. The text to be drawn may contain newline characters, which have the predictable effect.This method returns -1 if the text can't be displayed in the box specified by
beginText
. Use of this return value to measure and position text is discouraged, as it is inaccurate when mixing different font sizes on a line and can be plain wrong when the text box is nearly full. If exact sizing and positioning are a concern, please use theLayoutBox
class instead.- Parameters:
text
- the line of text to be drawn- Returns:
- the number of points required to render the lines to the document (zero or more), or -1 if the text box is full.
- Throws:
java.lang.IllegalStateException
- if no font or color is specified, or ifbeginText
hasn't been called first.- See Also:
LayoutBox
,PDFFont
-
beginTextLink
public void beginTextLink(PDFAction action, PDFStyle linkstyle)
Start a "link" section in the text. Any text displayed between here and the corresponding
endTextLink()
method call will act as aAnnotationLink
annotation, in the same way as the <A> tag does in HTML: When the user clicks on the text, the specified action is performed.Note that this method will not work as advertised if the position of the text has been modified via the
rotate(float, float, double)
method. This is a shortcoming inherent in the PDF document specification.- Parameters:
action
- the action to perform when the text is clicked onlinkstyle
- the style to apply to any text within the link area, ornull
if the current style is to be used. For an underlined link, usePDFStyle.LINKSTYLE
- Throws:
java.lang.IllegalStateException
- if a link has already been begun (links can't be nested)- Since:
- 1.1
- See Also:
AnnotationLink
,PDFStyle.LINKSTYLE
-
endTextLink
public PDFAnnotation[] endTextLink()
End the "link" section in the text, analogous to the </A> tag in HTML.
This method returns the list of annotations that were added - it's a list because if the link wrapped over several lines or pages, several annotations would have been added. The idea behind this is that you can add annotations to the text, and then set the actions they refer to (via the
AnnotationLink.setAction(org.faceless.pdf2.PDFAction)
method) after they've been added - for example, to link to a page that hasn't been created yet.- Throws:
java.lang.IllegalStateException
- if a link has not been begun- Since:
- 1.1
-
beginTag
public void beginTag(java.lang.String tag, java.util.Map<java.lang.String,java.lang.Object> atts)
Open a structural tag on this page. This call must be matched by a later call toendTag()
. See thePDFCanvas
version of this method for the full documnentation.- Specified by:
beginTag
in interfacePDFDrawable
- Parameters:
tag
- name of the tagatts
- user defined attributes for this tag, ornull
- Since:
- 2.11.9
- See Also:
PDFCanvas.beginTag(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>)
-
endTag
public void endTag()
Close a structural tag on this page. This call must match an earlier call tobeginTag()
See thePDFCanvas
version of this method for the full documnentation.- Specified by:
endTag
in interfacePDFDrawable
- Since:
- 2.11.9
- See Also:
PDFCanvas.beginTag(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>)
-
setThumbnail
public void setThumbnail(PDFImage image)
Set the embedded page thumbnail. Page thumbnails are not required, rarely used in modern PDFs and are ignore by many viewers (including Acrobat 9 or later). In most cases it's better to leave them unset as the viewer application will regenerate them. The exception is when pages are very large or complex, and a small file-size is not a consideration.- Parameters:
image
- the thumbmail image, which ideally should have a longest dimension <= 105px- Since:
- 2.11.18
-
getThumbnail
public PDFImage getThumbnail()
Return the thumbnail image on the page, as set bysetThumbnail(org.faceless.pdf2.PDFImage)
. May be null- Since:
- 2.11.18
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to this PDFPage.PropertyChangeEvent
s will be raised when various aspects of this annotation are changed
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a previously added PropertyChangeListener from this PDFPage.- Since:
- 2.11.19
- See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)
-
setMeasurementUnits
public void setMeasurementUnits(float x1, float y1, float x2, float y2, java.lang.String scale)
Set the natural scale for measurements in the specified area of the page. This value is used in Acrobat only for measuring distances or areas on the page, although it may be used elsewhere by other tools. It has no impact on any other coordinate systems used in the PDF API.- Parameters:
x1
- the X value of the lower-left corner of the rectangley1
- the Y value of the lower-left corner of the rectanglex2
- the X value of the upper-right corner of the rectangley2
- the Y value of the upper-right corner of the rectanglescale
- the scale, of the format "1pt = 20mm" - eg "10mm = 300mm", "1pt = 2in", "1in = 1mi".- Since:
- 2.14
-
putUserData
public void putUserData(java.lang.String key, java.lang.Object value)
Set a custom property on the PDF. The property will be saved with the file with the "BFOO_" prefix.- Parameters:
value
- a CharSequence, Number, Date, Calendar, Boolean, byte[], or a List/Map of those values, or null to remove the property- Since:
- 2.24.2
-
getUserData
public java.lang.Object getUserData(java.lang.String key)
Return a property previously set on the PDF with theputUserData()
method- Returns:
- a String, Boolean, Number, Calendar, byte[] or a Map/List of those values if found, or null if no such property exists.
- Since:
- 2.24.2
-
getAssociatedFiles
public java.util.Collection<EmbeddedFile> getAssociatedFiles()
Return the list of embedded files assocatiated with this PDFAnnotation. The list is live and can be edited. The ability to associate files with a PDFAnnotation is new in PDF 2.0.- Since:
- 2.26
- See Also:
AnnotationFile
-
createGraphics
public java.awt.Graphics2D createGraphics(PDF pdf)
Create aGraphics2D
object which can be used to write to this page. See thePDFCanvas.createGraphics(org.faceless.pdf2.PDF)
method for full documentation.- Parameters:
pdf
- the PDF - required, although if its specified as null it will use the value of page.getPDF()- Since:
- 2.26.3
-
getDocumentPart
public DocumentPart getDocumentPart()
Return theDocumentPart
this page belongs to, or null if it doesn't belong to any- Since:
- 2.28.3
-
toString
public java.lang.String toString()
-
putLiteral
public void putLiteral(java.lang.String key, java.lang.String tokens)
Put a literal token sequnce. For debugging- Parameters:
key
- the keytokens
- the token sequence, eg "true" or "/foo" or "[/Foo/Bar]". No refs, just direct objects.
-
clone
protected java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
-