public class PDFPage
extends com.qoppa.pdfViewer.hiObjects.AbstractPDFPage
Modifier and Type | Field and Description |
---|---|
static int |
COMPRESSION_DEFLATE |
static int |
COMPRESSION_JBIG2 |
static int |
COMPRESSION_JPEG |
Modifier and Type | Method and Description |
---|---|
void |
addAnnotation(Annotation annot)
Adds a new 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.
|
void |
appendPageContent(PDFPage srcPage,
double x,
double y,
double scaleX,
double scaleY,
Layer layer)
Adds the content of another page to this page.
|
boolean |
applyRedactionAnnotation(Redaction redactionAnnot)
This method will apply or "burn in" the redaction annotation.
|
boolean |
applyRedactionAnnotations()
This method will apply or "burn in" all redaction annotations that are on
this
PDFPage . |
Annotation |
copyAnnotation(Annotation annot)
Use this method to copy a single annotation onto this page, from this or other documents.
|
void |
copyAnnotations(PDFPage srcPage)
Use this method to copy annotations onto this page, from this or other
documents.
|
void |
copyAnnotations(PDFPage srcPage,
Layer layer)
Use this method to copy annotations onto this page, from this or other
documents.
|
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 |
drawImage(Image image,
int dstX,
int dstY,
int dstWidth,
int dstHeight,
Color bgndColor,
AffineTransform xform,
ImageParam params,
Float alpha)
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.
|
Object |
flattenAnnotation(Annotation annot)
Flatten an annotation into the content.
|
Object |
flattenAnnotations(boolean paintNonPrintableAnnots)
Flattens the annotations.
|
void |
flattenWidget(Widget widget)
Flatten a widget into the content layer of the page.
|
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.
|
BufferedImage |
getImageCS(int dpi,
ColorSpace imageCS)
Returns a BufferedImage, created in the given color space, containing a rendering of the page at the given resolution in DPI.
|
BufferedImage |
getImageGray(int dpi)
Returns a BufferedImage containing a rendering
of the page at the given resolution in DPI.
|
int |
getPageIndex()
Gets the page index of this page within the document.
|
String |
getPageLabel()
Returns the page label for this page.
|
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)
Returns an image for part of the page.
|
TextSelection |
getTextInArea(Rectangle2D selectArea)
Selects the text in an area of the page.
|
TextSelection |
getTextWithCursors(Point2D startCursor,
Point2D endCursor)
Returns the text contained between the start and end cursors, in "reading mode".
|
void |
insert_hOCR(String hocrText,
boolean renderText)
This methods inserts hOCR text into this page.
|
boolean |
isEmpty()
Check whether the page is empty.
|
void |
prependPageContent(PDFPage srcPage,
double x,
double y,
double scaleX,
double scaleY,
Layer layer)
Prepend the contents of another page to this page.
|
void |
removeAnnotation(Annotation annot)
Removes an annotation from this page.
|
void |
savePageAsGIF(OutputStream outStream,
int dpi)
Render the page as an image and save it to the output stream in PNG format.
|
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)
Sets the clip area in the page's content stream when drawing to the page.
|
void |
setCropBox(Rectangle2D rect)
Sets the PDF page's 'CropBox'.
|
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,
String blendName) |
addField, drawAnnotations, findLinesMatchingRegex, findTextWithContext, getAbstractPDFDocument, getAdditionalActions, getAnnotations, getArtBox, getBleedBox, getColorSpace, getCropBox, getDisplayHeight, getDisplayWidth, getDisplayX, getDisplayY, getIDocument, getImage, getImageModel, getImageWithoutText, getImageWithoutTextGray, getMediaBox, getPageRotation, getPageTransForm, getPDFGraphicsOperators, getShapes, getTabbingOrder, getText, getTextModel, getTrimBox, hasText, invalidateTextModel, pageHasNoText, paintPage, paintPage, paintPageContent, printPage
public static final int COMPRESSION_DEFLATE
public static final int COMPRESSION_JBIG2
public static final int COMPRESSION_JPEG
public void addAnnotation(Annotation annot) throws PDFException
annot
- The annotation to add.PDFException
public void addJPEGImage(File jpegFile, int x, int y, AffineTransform xform) throws PDFException, IOException
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.PDFException
IOException
public SignatureField addSignatureField(String fieldName, Rectangle2D bounds) throws PDFException
PDFDocument.signDocument
.
To create an invisible signature field, the bound rectangle should be set to (0,0,0,0) for the bounds.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.PDFException
public void appendPageContent(PDFPage srcPage, double x, double y, double scaleX, double scaleY, Layer layer) throws PDFException
srcPage
- The source page to take the content stream from.x
- The X position on the destination page at which the upper left
corner of the source page will be placed.y
- The Y position on the destination page at which the upper left
corner of the source page will be placed.scaleX
- Horizontal scale to apply to the source page before adding it
to the destination page. The scale is 1 based, 1 = full scale.scaleY
- Vertical scale to apply to the source page before adding it to
the destination page. The scale is 1 based, 1 = full scale.layer
- The layer to append the source page content stream, or null.PDFException
IllegalArgumentException
- if layer is not null, layer must be from the target documentprependPageContent(PDFPage, double, double, double, double, Layer)
public Annotation copyAnnotation(Annotation annot) throws PDFException
PDFException
public void copyAnnotations(PDFPage srcPage) throws PDFException
srcPage
- The source page to copy annotations fromPDFException
public void copyAnnotations(PDFPage srcPage, Layer layer) throws PDFException
PDFPage
's PDFDocument
.srcPage
- The source page to copy annotations fromlayer
- The layer to add the annotations to, may be nullPDFException
public Graphics2D createGraphics() throws PDFException
PDFException
public Graphics2D createGraphics(Layer layer) throws PDFException
layer
- The layer to draw into. This object must be created through PDFDocument.addLayer()PDFException
public void deleteAnnotations() throws PDFException
PDFException
public void drawImage(Image image, int dstX, int dstY, Color bgndColor, AffineTransform xform, ImageParam params) throws PDFException
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.PDFException
public void drawImage(Image image, int dstX, int dstY, int dstWidth, int dstHeight, Color bgndColor, AffineTransform xform, ImageParam params) throws PDFException
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.PDFException
public void drawImage(Image image, int dstX, int dstY, int dstWidth, int dstHeight, Color bgndColor, AffineTransform xform, ImageParam params, Float alpha) throws PDFException
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.alpha
- The alpha component to display the image with transparencyPDFException
public void drawText(String str, Font font, Paint textPaint, double x, double y, AffineTransform xform) throws PDFException
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.PDFException
public void fillShape(Shape shape, Paint shapePaint, double offsetX, double offsetY, AffineTransform xform)
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 the shape, in 72 DPI.xform
- A transform to apply to the shape before drawing it to the page.public Vector findText(String searchText, boolean caseSensitive, boolean wholeWords) throws PDFException
findText
in interface IPDFPage
findText
in class com.qoppa.pdfViewer.hiObjects.AbstractPDFPage
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.PDFException
public TextSelection getTextWithCursors(Point2D startCursor, Point2D endCursor) throws PDFException
getTextWithCursors
in interface IPDFPage
getTextWithCursors
in class com.qoppa.pdfViewer.hiObjects.AbstractPDFPage
startCursor
- the location where the cursor should start selectionendCursor
- The location where the cursor ends selectionPDFException
public TextSelection getTextInArea(Rectangle2D selectArea) throws PDFException
getTextInArea
in interface IPDFPage
getTextInArea
in class com.qoppa.pdfViewer.hiObjects.AbstractPDFPage
PDFException
public Object flattenAnnotation(Annotation annot) throws PDFException
annot
- The annotation to flatten.PDFException
public Object flattenAnnotations(boolean paintNonPrintableAnnots) throws PDFException
paintNonPrintableAnnots
- Flag to indicate whether non-printable annotations should be
painted or not.PDFException
public void flattenWidget(Widget widget) throws PDFException
widget
- The widget to flattenPDFException
public PDFDocument getDocument()
public BufferedImage getImage() throws PDFException
PDFException
public BufferedImage getImageCS(int dpi, ColorSpace imageCS) throws PDFException
dpi
- Dots per inch at which to render the image.imageCS
- The color space to use when creating the image.PDFException
public BufferedImage getImage(int dpi) throws PDFException
dpi
- Dots per inch at which to render the image.PDFException
public BufferedImage getImageGray(int dpi) throws PDFException
dpi
- Dots per inch at which to render the image.PDFException
public int getPageIndex()
getPageIndex
in interface IPDFPage
getPageIndex
in class com.qoppa.pdfViewer.hiObjects.AbstractPDFPage
public String getPageLabel() throws PDFException
PDFException
public double getPaperHeight()
public double getPaperWidth()
public BufferedImage getSubImage(Rectangle2D pageArea, int dpi) throws PDFException
pageArea
- The area of the page to get an image for.dpi
- The desired resolution for the image.PDFException
public boolean isEmpty() throws PDFException
PDFException
public void prependPageContent(PDFPage srcPage, double x, double y, double scaleX, double scaleY, Layer layer) throws PDFException
srcPage
- The source page to take the content stream from.x
- The X position on the destination page at which the upper left
corner of the source page will be placedy
- The Y position on the destination page at which the upper left
corner of the source page will be placedscaleX
- Horizontal scale to apply to the source page before adding it
to the destination page.scaleY
- Vertical scale to apply to the source page before adding it to
the destination page.layer
- The layer to append the source page content stream, or null.PDFException
IllegalArgumentException
- if layer is not null, layer must be from the target documentappendPageContent(PDFPage, double, double, double, double, Layer)
public void removeAnnotation(Annotation annot) throws PDFException
annot
- A reference to the annotation that needs to be removed.PDFException
public void savePageAsGIF(OutputStream outStream, int dpi) throws PDFException, IOException
outStream
- The stream to save the image to.dpi
- Dots per inch at which to render the image. 72 is the native PDF resolution.PDFException
IOException
public void savePageAsJPEG(OutputStream outStream, int dpi, float quality) throws IOException, PDFException
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.IOException
PDFException
public void savePageAsPNG(OutputStream outStream, int dpi) throws PDFException, IOException
outStream
- The stream to save the image to.dpi
- Dots per inch at which to render the image. 72 is the native PDF resolution.PDFException
IOException
public void savePageAsTIFF(OutputStream outStream, double resDPI, String tiffCompression) throws IOException, PDFException
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:IOException
PDFException
public void savePageAsTIFF(OutputStream outStream, TIFFOptions options) throws IOException, PDFException
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.IOException
PDFException
public void setArtBox(Rectangle2D rect)
public void setBleedBox(Rectangle2D rect)
public void setClip(Area newClip) throws PDFException
newClip
- The new clip area.PDFException
public void setCropBox(Rectangle2D rect) throws PDFException
PDFException
public void setPageRotation(int degrees) throws PDFException
degrees
- The new page rotation, in degreesPDFException
public void setTrimBox(Rectangle2D rect)
public void strokeShape(Shape shape, Paint shapePaint, double offsetX, double offsetY, AffineTransform xform)
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 the shape, in 72 DPI.xform
- A transform to apply to the shape before drawing it to the page.public String useGradientPaint(GradientPaint paint) throws PDFException
PDFException
public String useGState(double strokeAlpha, double fillAlpha, String blendName) throws PDFException
PDFException
public void insert_hOCR(String hocrText, boolean renderText) throws PDFException
hocrText
- The hOCR text content.renderText
- Flag indicating whethet the text should be shown on the page. If the flag is false, the text is added in "No Render" mode.
Text that uses this mode is present in the page and it is selectable, but it is not visible.PDFException
public boolean applyRedactionAnnotations() throws PDFException
PDFPage
. The page content that is contained within the
redaction annotation's bounds will be redacted.PDFPage
contains ANY redaction annotations that were burned in. If there are no
redaction annotations, this method returns false.
otherwise false.PDFException
public boolean applyRedactionAnnotation(Redaction redactionAnnot) throws PDFException
PDFPage
. The
page content that is contained within the redaction annotation's bounds
will be redacted.PDFPage
contains the redaction annotation that was passed in and the content was redacted, false otherwise.PDFException