com.qoppa.pdfProcess
Class PDFPage

java.lang.Object
  extended bycom.qoppa.pdfViewer.hiObjects.AbstractPDFPage
      extended bycom.qoppa.pdfProcess.PDFPage
All Implemented Interfaces:
IPDFPage

public class PDFPage
extends AbstractPDFPage
implements IPDFPage

This class holds a page in a PDF document.

Author:
Qoppa Software

Field Summary
static int COMPRESSION_DEFLATE
           
static int COMPRESSION_JBIG2
           
static int COMPRESSION_JPEG
           
 
Method Summary
 void addAnnotation(Annotation annot)
          Adds an annotation to this page.
 void addJPEGImage(File jpegFile, int x, int y, AffineTransform xform)
          Adds a JPEG image onto this page.
 SignatureField addSignatureField(String fieldName, Rectangle2D bounds)
          Adds a signature field to this page.
 Graphics2D createGraphics()
          Creates a Graphics2D object to draw into this page.
 Graphics2D createGraphics(Layer layer)
          Creates a graphics object that encapsulates a layer in a PDF document.
 void deleteAnnotations()
          Delete all annotations from the page.
 void drawImage(Image image, int dstX, int dstY, Color bgndColor, AffineTransform xform, ImageParam params)
          Draws an image onto this page.
 void drawImage(Image image, int dstX, int dstY, int dstWidth, int dstHeight, Color bgndColor, AffineTransform xform, ImageParam params)
          Draws an image onto this page.
 void drawText(String str, Font font, Paint textPaint, double x, double y, AffineTransform xform)
          Draws text onto this page.
 void fillShape(Shape shape, Paint shapePaint, double offsetX, double offsetY, AffineTransform xform)
          Fills a shape on this page.
 Vector findText(String searchText, boolean caseSensitive, boolean wholeWords)
          Searches the page for text and returns a list of TextPosition objects for each of the occurrences of the string in the page.
 void flattenAnnotation(Annotation annot)
          Flatten the given annotation.
 void flattenAnnotations(boolean paintNonPrintableAnnots)
          Flattens the annotations.
 void flattenWidget(Widget widget)
          Flatten a widget into the content layer of the page.
 Vector getAnnotations()
          Returns a list of PDF annotations in this page.
 Rectangle2D getArtBox()
          Return this page's Art Box.
 Rectangle2D getBleedBox()
          Return this page's Bleed Box.
 Rectangle2D getCropBox()
          Returns the PDF page's 'CropBox'.
 double getDisplayHeight()
          Returns the display height of this page in 72 DPI.
 double getDisplayWidth()
          Returns the display width of this page in 72 DPI.
 double getDisplayX()
          Returns the page's left margin.
 double getDisplayY()
          Returns the page's top margin.
 PDFDocument getDocument()
          Returns the document that this page belongs to.
 BufferedImage getImage()
          Returns a BufferedImage containing a rendering of the page at the default PDF resolution: 72 DPI.
 BufferedImage getImage(int dpi)
          Returns a BufferedImage containing a rendering of the page at the given resolution in DPI.
 Rectangle2D getMediaBox()
          Returns the PDF page's 'MediaBox'.
 int getPageIndex()
          Gets the page index of this page within the document.
 int getPageRotation()
          Returns the rotation of this page in degrees.
 double getPaperHeight()
          Returns the paper's height of this page in 72 DPI.
 double getPaperWidth()
          Returns the paper's width of this page in 72 DPI.
 BufferedImage getSubImage(Rectangle2D pageArea, int dpi)
           
 Rectangle2D getTrimBox()
          Return this page's Trim Box.
 void invalidate()
          Invalidate paint cache.
 void removeAnnotation(Annotation annot)
          Removes an annotation from this page.
 void savePageAsJPEG(OutputStream outStream, int dpi, float quality)
          Render the page as an image and save it to the output stream in JPEG format.
 void savePageAsPNG(OutputStream outStream, int dpi)
          Render the page as an image and save it to the output stream in PNG format.
 void savePageAsTIFF(OutputStream outStream, double resDPI, String tiffCompression)
          Save the rendering image of the page to the given OutputStream in TIFF format.
 void savePageAsTIFF(OutputStream outStream, TIFFOptions options)
          Render the page to an image and save it in TIFF format to the given OutputStream.
 void setArtBox(Rectangle2D rect)
          Sets this page's Art Box.
 void setBleedBox(Rectangle2D rect)
          Sets this page's Bleed Box.
 void setClip(Area newClip)
           
 void setCropBox(Rectangle2D rect)
          Sets the PDF page's 'CropBox'.
 void setDocument(PDFDocument parentDoc)
           
 void setPageRotation(int degrees)
          Changes this page's rotation.
 void setTrimBox(Rectangle2D rect)
          Sets this page's Trim Box.
 void strokeShape(Shape shape, Paint shapePaint, double offsetX, double offsetY, AffineTransform xform)
          Draws the outline of a shape on this page.
 String useGradientPaint(GradientPaint paint)
           
 String useGState(double strokeAlpha, double fillAlpha)
           
 void writeAnnotsAsFDF(PDFArray annotsArray, int pageIndex)
          Internal do not use.
 void writeAnnotsAsXFDF(nanoxml.XMLElement topElement, Integer pageIndex)
          Internal do not use
 
Methods inherited from class com.qoppa.pdfViewer.hiObjects.AbstractPDFPage
clearTextSelection, getImage, getSelectedText, getStringPositionInfo, paintPage, printPage, selectText, setInvertMode, setSelectedText
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.qoppa.pdf.dom.IPDFPage
clearTextSelection, getImage, getSelectedText, paintPage, printPage, selectText, setInvertMode
 

Field Detail

COMPRESSION_JPEG

public static final int COMPRESSION_JPEG
See Also:
Constant Field Values

COMPRESSION_DEFLATE

public static final int COMPRESSION_DEFLATE
See Also:
Constant Field Values

COMPRESSION_JBIG2

public static final int COMPRESSION_JBIG2
See Also:
Constant Field Values
Method Detail

getAnnotations

public Vector getAnnotations()
                      throws PDFException
Returns a list of PDF annotations in this page. The objects in the Vector are all derived from com.qoppa.pdf.annotations.Annotation.

Specified by:
getAnnotations in interface IPDFPage
Returns:
List of annotations.
Throws:
PDFException

createGraphics

public Graphics2D createGraphics()
                          throws PDFException
Creates a Graphics2D object to draw into this page. Anything drawn to this graphics object will be drawn onto the PDF page and can then be saved into a PDF document or printed. New content will be drawn on top of the current page content.

The Graphics2D object will initially have its origin on the upper left corner of the page's crop box (the visible area of the page).

Returns:
Graphics2D Graphics object used to draw into this page.
Throws:
PDFException

createGraphics

public Graphics2D createGraphics(Layer layer)
                          throws PDFException
Creates a graphics object that encapsulates a layer in a PDF document. When drawing to this graphics object, all elements will be drawn into a new layer (optional content group) in the pdf document.

The Graphics2D object will initially have its origin on the upper left corner of the page's crop box (the visible area of the page).

Parameters:
layer - The layer to draw into. This object must be created through PDFDocument.addLayer()
Returns:
A Graphics2D object that can be drawn into.
Throws:
PDFException

getCropBox

public Rectangle2D getCropBox()
Returns the PDF page's 'CropBox'. The CropBox is a rectangle that is used to crop content before displaying or printing the page. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.

Specified by:
getCropBox in interface IPDFPage
Returns:
Rectangle2D This page's CropBox

getImage

public BufferedImage getImage()
                       throws PDFException
Returns a BufferedImage containing a rendering of the page at the default PDF resolution: 72 DPI.

Throws:
PDFException

getImage

public BufferedImage getImage(int dpi)
                       throws PDFException
Returns a BufferedImage containing a rendering of the page at the given resolution in DPI.

Parameters:
dpi - Dots per inch at which to render the image.
Returns:
A BufferedImage object of the page at the requested DPI.
Throws:
PDFException

getSubImage

public BufferedImage getSubImage(Rectangle2D pageArea,
                                 int dpi)
                          throws PDFException
Throws:
PDFException

savePageAsJPEG

public void savePageAsJPEG(OutputStream outStream,
                           int dpi,
                           float quality)
                    throws IOException,
                           PDFException
Render the page as an image and save it to the output stream in JPEG format.

Parameters:
outStream - The stream to save the image to.
dpi - Dots per inch at which to render the image. 72 is the native PDF resolution.
quality - The quality setting to use for JPEG compression. The range for this value is 0.0 to 1.0. Lower values mean higher compression and lower quality. As a guideline, 0.25 is low quality, 0.5 is medium quality and 0.75 is high quality.
Throws:
IOException
PDFException

savePageAsPNG

public void savePageAsPNG(OutputStream outStream,
                          int dpi)
                   throws PDFException,
                          IOException
Render the page as an image and save it to the output stream in PNG format.

Parameters:
outStream - The stream to save the image to.
dpi - Dots per inch at which to render the image. 72 is the native PDF resolution.
Throws:
PDFException
IOException

savePageAsTIFF

public void savePageAsTIFF(OutputStream outStream,
                           double resDPI,
                           String tiffCompression)
                    throws IOException,
                           PDFException
Save the rendering image of the page to the given OutputStream in TIFF format. The image will be converted to black and white and fax compression will be used. resDPI is the resolution in DPI used to render the page, 72 is the recommended value for the resolution.
This method requires Java Advanced Imaging (JAI) classes in the class path (jai_codec.jar). See our documentation regarding Distribution and JAR Files for more info.

Parameters:
outStream - The stream to save the image to.
resDPI - Dots per inch at which to render the image.
tiffCompression - The type of TIFF compression to use. This value needs to be one of these predefined values:

TIFFCompressionTIFF_DEFLATE - Deflate lossless compression (Zip-in-TIFF)
TIFFCompressionTIFF_CCITT_RLE - CCITT Modified Huffman RLE
TIFFCompressionTIFF_CCITT_T4 - CCITT Group 3 fax encoding
TIFFCompressionTIFF_CCITT_T6 - CCITT Group 4 fax encoding
TIFFCompressionTIFF_JPEG - JPEG-in-TIFF compression.
TIFFCompressionTIFF_LZW - LZW Compression
TIFFCompressionTIFF_PACKBITS - Byte-oriented run-length encoding "PackBits" compression.
TIFFCompressionTIFF_ZLIB - ZLib Compression.
TIFFCompressionTIFF_NO_COMPRESSION - No compression.
Throws:
IOException
PDFException

savePageAsTIFF

public void savePageAsTIFF(OutputStream outStream,
                           TIFFOptions options)
                    throws IOException,
                           PDFException
Render the page to an image and save it in TIFF format to the given OutputStream. If fax compression is used, the image will be converted automatically to black and white.
This method requires Java Advanced Imaging (JAI) classes in the class path (jai_codec.jar). See our documentation regarding Distribution and JAR Files for more info.

Parameters:
outStream - The stream to save the image to.
options - Options when saving the image, such as the output DPI, the TIFF compression method and more.
Throws:
IOException
PDFException

getMediaBox

public Rectangle2D getMediaBox()
Returns the PDF page's 'MediaBox'. The MediaBox is a rectangle that defines the size of the Media that this page was designed for, this roughly corresponds to the page size when printing.

Specified by:
getMediaBox in interface IPDFPage
Returns:
Rectangle2D This page's MediaBox

getPaperHeight

public double getPaperHeight()
Returns the paper's height of this page in 72 DPI. This values comes from the page's MediaBox.

Returns:
double Height of this page

getPaperWidth

public double getPaperWidth()
Returns the paper's width of this page in 72 DPI. This values comes from the page's MediaBox.

Returns:
double Width of this page

getDisplayWidth

public double getDisplayWidth()
Returns the display width of this page in 72 DPI. This value comes from the pages CropBox

Specified by:
getDisplayWidth in interface IPDFPage
Returns:
double Width of this page

getDisplayHeight

public double getDisplayHeight()
Returns the display height of this page in 72 DPI. This value comes from the pages CropBox

Specified by:
getDisplayHeight in interface IPDFPage
Returns:
double Width of this page

getDisplayX

public double getDisplayX()
Description copied from interface: IPDFPage
Returns the page's left margin. This value correspond to the different between the page's CropBox X coordinate and the MediaBox X coordinate. When the page is, this will be the origin of the displayed page.

Specified by:
getDisplayX in interface IPDFPage
Returns:
The page's display X coordinate.

getDisplayY

public double getDisplayY()
Description copied from interface: IPDFPage
Returns the page's top margin. This value correspond to the different between the page's CropBox Y coordinate and the MediaBox Y coordinate. When the page is, this will be the origin of the displayed page.

Specified by:
getDisplayY in interface IPDFPage
Returns:
The page's display Y coordinate.

getPageRotation

public int getPageRotation()
Returns the rotation of this page in degrees.

Specified by:
getPageRotation in interface IPDFPage
Returns:
int Page rotation in degrees.

setPageRotation

public void setPageRotation(int degrees)
Changes this page's rotation.

Parameters:
degrees - The new page rotation, in degrees

getDocument

public PDFDocument getDocument()
Returns the document that this page belongs to. A PDFPage can only belong to a single document at a time.

Returns:
The parent document.

invalidate

public void invalidate()
Invalidate paint cache.


addAnnotation

public void addAnnotation(Annotation annot)
                   throws PDFException
Adds an annotation to this page.

Parameters:
annot - The annotation to add.
Throws:
PDFException

addSignatureField

public SignatureField addSignatureField(String fieldName,
                                        Rectangle2D bounds)
                                 throws PDFException
Adds a signature field to this page. The signature field is added to the page but is NOT signed. To sign the document, the application must call PDFDocument.signDocument. To create an invisible signature field, the bound rectangle should be set to (0,0,0,0) for the bounds.

Parameters:
fieldName - The name of the new field.
bounds - The bounds of the field on the page. (0,0,0,0) indicates that the signature field will be invisible.
Throws:
PDFException

getPageIndex

public int getPageIndex()
Gets the page index of this page within the document. Page index starts at 0.

Returns:
int This page's index

removeAnnotation

public void removeAnnotation(Annotation annot)
                      throws PDFException
Removes an annotation from this page.

Parameters:
annot - A reference to the annotation that needs to be removed.
Throws:
PDFException

drawImage

public void drawImage(Image image,
                      int dstX,
                      int dstY,
                      Color bgndColor,
                      AffineTransform xform,
                      ImageParam params)
               throws PDFException
Draws an image onto this page. The image will be drawn at the specified dstX, dstY location and will not be scaled except for any transform passed into the method.

Parameters:
image - The image to draw.
dstX - The horizontal position of the image in 72 DPI.
dstY - The vertical position of the image in 72 DPI.
bgndColor - The background color if any. If this parameter is not null, the method will first fill a rectangle with this color where the image will be drawn, then draw the image on top.
xform - A transform to apply to the image before drawing it to the page. This parameter can be left null for no transform.
params - An ImageParam object describing what compression to use when writing images to the PDF document. If null, the library will use default settings.
Throws:
PDFException

drawImage

public void drawImage(Image image,
                      int dstX,
                      int dstY,
                      int dstWidth,
                      int dstHeight,
                      Color bgndColor,
                      AffineTransform xform,
                      ImageParam params)
               throws PDFException
Draws an image onto this page. The image will be scaled to dstWidth and dstHeight. If dstWidth or dstHeight are set to 0, the method will get the destination width and/or height from the image size.

Parameters:
image - The image to draw.
dstX - The horizontal position of the image in 72 DPI.
dstY - The vertical position of the image in 72 DPI.
dstWidth - The width on the page that the image will occupy. If this is <= 0, the method will use the image's width.
dstHeight - The height on the page that the image will occupy. If this is <= 0, the method will use the image's height.
bgndColor - The background color if any. If this parameter is not null, the method will first fill a rectangle with this color where the image will be drawn, then draw the image on top.
xform - A transform to apply to the image before drawing it to the page. This parameter can be left null for no transform.
params - An ImageParam object describing what compression to use when writing images to the PDF document. If null, the library will use default settings.
Throws:
PDFException

addJPEGImage

public void addJPEGImage(File jpegFile,
                         int x,
                         int y,
                         AffineTransform xform)
                  throws PDFException,
                         IOException
Adds a JPEG image onto this page.

Parameters:
jpegFile - The JPEG file.
x - The horizontal position of the image in 72 DPI.
y - The vertical position of the image in 72 DPI.
xform - A transform to apply to the image before drawing it to the page. This parameter can be left null for no transform.
Throws:
PDFException
IOException

fillShape

public void fillShape(Shape shape,
                      Paint shapePaint,
                      double offsetX,
                      double offsetY,
                      AffineTransform xform)
Fills a shape on this page.

Parameters:
shape - The shape to fill.
shapePaint - The color to use when filling the shape.
offsetX - A horizontal offset to apply before drawing the shape, in 72 DPI.
offsetY - A vertical offset to apply before drawing teh shape, in 72 DPI.
xform - A transform to apply to the shape before drawing it to the page.

flattenAnnotation

public void flattenAnnotation(Annotation annot)
                       throws PDFException
Flatten the given annotation. This makes the annotation uneditable and merges the content of the annotation with the page.

Parameters:
annot - The annotation to flatten into the content layer.
Throws:
PDFException

flattenAnnotations

public void flattenAnnotations(boolean paintNonPrintableAnnots)
                        throws PDFException
Flattens the annotations. This makes the annotations uneditable and merges the content of the annotations with the page.

Parameters:
paintNonPrintableAnnots - Flag to indicate whether non-printable annotations should be painted or not.
Throws:
PDFException

deleteAnnotations

public void deleteAnnotations()
                       throws PDFException
Delete all annotations from the page. This removes all the annotations in the PDF page.

Throws:
PDFException

flattenWidget

public void flattenWidget(Widget widget)
                   throws PDFException
Flatten a widget into the content layer of the page. After flattening the widget, the widget is removed from the list of widgets in the page.

Parameters:
widget - The widget to flatten
Throws:
PDFException

strokeShape

public void strokeShape(Shape shape,
                        Paint shapePaint,
                        double offsetX,
                        double offsetY,
                        AffineTransform xform)
Draws the outline of a shape on this page.

Parameters:
shape - The shape whose outline will be drawn.
shapePaint - The color to use when drawing the outline of the shape.
offsetX - A horizontal offset to apply before drawing the shape, in 72 DPI.
offsetY - A vertical offset to apply before drawing teh shape, in 72 DPI.
xform - A transform to apply to the shape before drawing it to the page.

drawText

public void drawText(String str,
                     Font font,
                     Paint textPaint,
                     double x,
                     double y,
                     AffineTransform xform)
              throws PDFException
Draws text onto this page.

Parameters:
str - The string to draw on the page.
font - The font to use when drawing the text.
textPaint - The color to use when drawing the text.
x - The horizontal position of the text on the page, in 72 DPI.
y - The vertical position of the text on the page, in 72 DPI.
xform - A transform to apply to the text before drawing it to the page.
Throws:
PDFException

getBleedBox

public Rectangle2D getBleedBox()
Return this page's Bleed Box. A page should be clipped to this coordinates when output to a production environment. jPDFProcess does not use the Bleed Box, it uses the Crop Box to clip a page before printing. The method is provided for information to the host application. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.

Specified by:
getBleedBox in interface IPDFPage
Returns:
The page's bleed box.

getTrimBox

public Rectangle2D getTrimBox()
Return this page's Trim Box. The trim box defines a finished page's intended dimension after trimming. jPDFProcess does not use the Trim Box, the method is provided here for information to the host application. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.

Specified by:
getTrimBox in interface IPDFPage
Returns:
The page's crop box.

getArtBox

public Rectangle2D getArtBox()
Return this page's Art Box. The art box defines the extent of the page's meaningful content (including potential whitespace). jPDFViewer does not use the Art Box, the method is provided here for information to the host application. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.

Specified by:
getArtBox in interface IPDFPage
Returns:
The page's art box.

setCropBox

public void setCropBox(Rectangle2D rect)
Sets the PDF page's 'CropBox'. The CropBox is a rectangle that is used to crop content before displaying or printing the page. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.


setBleedBox

public void setBleedBox(Rectangle2D rect)
Sets this page's Bleed Box. A page should be clipped to this coordinates when output to a production environment. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.


setTrimBox

public void setTrimBox(Rectangle2D rect)
Sets this page's Trim Box. The trim box defines a finished page's intended dimension after trimming. This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.


setArtBox

public void setArtBox(Rectangle2D rect)
Sets this page's Art Box. The art box defines the extent of the page's meaningful content (including potential whitespace). This rectangle is in PDF native coordinates starting at the bottom left and increasing up to the right.


writeAnnotsAsFDF

public void writeAnnotsAsFDF(PDFArray annotsArray,
                             int pageIndex)
Internal do not use. This method adds all annotations dictionary EXCLUDING LINKS to a PDFArray. This method is used to export annotations as FDF.


writeAnnotsAsXFDF

public void writeAnnotsAsXFDF(nanoxml.XMLElement topElement,
                              Integer pageIndex)
                       throws PDFException
Internal do not use

Throws:
PDFException

useGradientPaint

public String useGradientPaint(GradientPaint paint)
                        throws PDFException
Throws:
PDFException

useGState

public String useGState(double strokeAlpha,
                        double fillAlpha)
                 throws PDFException
Throws:
PDFException

setDocument

public void setDocument(PDFDocument parentDoc)

setClip

public void setClip(Area newClip)
             throws PDFException
Throws:
PDFException

findText

public Vector findText(String searchText,
                       boolean caseSensitive,
                       boolean wholeWords)
                throws PDFException
Searches the page for text and returns a list of TextPosition objects for each of the occurrences of the string in the page. If there are no occurrences, the method returns a Vector of length 0.

Parameters:
searchText - The text to search for.
caseSensitive - Flag indicating whether the search should be case sensitive.
wholeWords - Flag indicating whether the search should only look at whole words.
Returns:
A list of TextPosition objects.
Throws:
PDFException