public class PDFRenderer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private AnnotationFilter |
annotationFilter
Default annotations filter, returns all annotations
|
private RenderDestination |
defaultDestination |
protected PDDocument |
document |
private static boolean |
kcmsLogged |
private static org.apache.commons.logging.Log |
LOG |
private java.awt.image.BufferedImage |
pageImage |
private java.awt.RenderingHints |
renderingHints |
private boolean |
subsamplingAllowed |
Constructor and Description |
---|
PDFRenderer(PDDocument document)
Creates a new PDFRenderer.
|
Modifier and Type | Method and Description |
---|---|
private java.awt.RenderingHints |
createDefaultRenderingHints(java.awt.Graphics2D graphics) |
protected PageDrawer |
createPageDrawer(PageDrawerParameters parameters)
Returns a new PageDrawer instance, using the given parameters.
|
AnnotationFilter |
getAnnotationsFilter()
Return the AnnotationFilter.
|
RenderDestination |
getDefaultDestination() |
(package private) java.awt.image.BufferedImage |
getPageImage()
Returns the image to which the current page is being rendered.
|
java.awt.RenderingHints |
getRenderingHints()
Get the rendering hints.
|
private boolean |
hasBlendMode(PDPage page) |
private boolean |
isBitonal(java.awt.Graphics2D graphics) |
private static boolean |
isGoodVersion(java.lang.String version,
java.lang.String regex,
int min) |
boolean |
isGroupEnabled(PDOptionalContentGroup group)
Indicates whether an optional content group is enabled.
|
private static boolean |
isMinJdk8() |
boolean |
isSubsamplingAllowed()
Value indicating if the renderer is allowed to subsample images before drawing, according to
image dimensions and requested scale.
|
java.awt.image.BufferedImage |
renderImage(int pageIndex)
Returns the given page as an RGB image at 72 DPI
|
java.awt.image.BufferedImage |
renderImage(int pageIndex,
float scale)
Returns the given page as an RGB image at the given scale.
|
java.awt.image.BufferedImage |
renderImage(int pageIndex,
float scale,
ImageType imageType)
Returns the given page as an RGB or ARGB image at the given scale.
|
java.awt.image.BufferedImage |
renderImage(int pageIndex,
float scale,
ImageType imageType,
RenderDestination destination)
Returns the given page as an RGB or ARGB image at the given scale.
|
java.awt.image.BufferedImage |
renderImageWithDPI(int pageIndex,
float dpi)
Returns the given page as an RGB image at the given DPI.
|
java.awt.image.BufferedImage |
renderImageWithDPI(int pageIndex,
float dpi,
ImageType imageType)
Returns the given page as an RGB image at the given DPI.
|
void |
renderPageToGraphics(int pageIndex,
java.awt.Graphics2D graphics)
Renders a given page to an AWT Graphics2D instance at 72 DPI.
|
void |
renderPageToGraphics(int pageIndex,
java.awt.Graphics2D graphics,
float scale)
Renders a given page to an AWT Graphics2D instance.
|
void |
renderPageToGraphics(int pageIndex,
java.awt.Graphics2D graphics,
float scaleX,
float scaleY)
Renders a given page to an AWT Graphics2D instance.
|
void |
renderPageToGraphics(int pageIndex,
java.awt.Graphics2D graphics,
float scaleX,
float scaleY,
RenderDestination destination)
Renders a given page to an AWT Graphics2D instance.
|
void |
setAnnotationsFilter(AnnotationFilter annotationsFilter)
Set the AnnotationFilter.
|
void |
setDefaultDestination(RenderDestination defaultDestination) |
void |
setRenderingHints(java.awt.RenderingHints renderingHints)
Set the rendering hints.
|
void |
setSubsamplingAllowed(boolean subsamplingAllowed)
Sets a value instructing the renderer whether it is allowed to subsample images before
drawing.
|
private static void |
suggestKCMS() |
private void |
transform(java.awt.Graphics2D graphics,
PDPage page,
float scaleX,
float scaleY) |
private static final org.apache.commons.logging.Log LOG
protected final PDDocument document
private AnnotationFilter annotationFilter
private boolean subsamplingAllowed
private RenderDestination defaultDestination
private java.awt.RenderingHints renderingHints
private java.awt.image.BufferedImage pageImage
private static boolean kcmsLogged
public PDFRenderer(PDDocument document)
document
- the document to renderpublic AnnotationFilter getAnnotationsFilter()
public void setAnnotationsFilter(AnnotationFilter annotationsFilter)
Allows to only render annotation accepted by the filter.
annotationsFilter
- the AnnotationFilterpublic boolean isSubsamplingAllowed()
public void setSubsamplingAllowed(boolean subsamplingAllowed)
subsamplingAllowed
- The new value indicating if subsampling is allowed.public RenderDestination getDefaultDestination()
public void setDefaultDestination(RenderDestination defaultDestination)
defaultDestination
- the defaultDestination to setpublic java.awt.RenderingHints getRenderingHints()
public void setRenderingHints(java.awt.RenderingHints renderingHints)
renderingHints
- public java.awt.image.BufferedImage renderImage(int pageIndex) throws java.io.IOException
pageIndex
- the zero-based index of the page to be converted.java.io.IOException
- if the PDF cannot be readpublic java.awt.image.BufferedImage renderImage(int pageIndex, float scale) throws java.io.IOException
pageIndex
- the zero-based index of the page to be convertedscale
- the scaling factor, where 1 = 72 DPIjava.io.IOException
- if the PDF cannot be readpublic java.awt.image.BufferedImage renderImageWithDPI(int pageIndex, float dpi) throws java.io.IOException
pageIndex
- the zero-based index of the page to be converteddpi
- the DPI (dots per inch) to render atjava.io.IOException
- if the PDF cannot be readpublic java.awt.image.BufferedImage renderImageWithDPI(int pageIndex, float dpi, ImageType imageType) throws java.io.IOException
pageIndex
- the zero-based index of the page to be converteddpi
- the DPI (dots per inch) to render atimageType
- the type of image to returnjava.io.IOException
- if the PDF cannot be readpublic java.awt.image.BufferedImage renderImage(int pageIndex, float scale, ImageType imageType) throws java.io.IOException
pageIndex
- the zero-based index of the page to be convertedscale
- the scaling factor, where 1 = 72 DPIimageType
- the type of image to returnjava.io.IOException
- if the PDF cannot be readpublic java.awt.image.BufferedImage renderImage(int pageIndex, float scale, ImageType imageType, RenderDestination destination) throws java.io.IOException
pageIndex
- the zero-based index of the page to be convertedscale
- the scaling factor, where 1 = 72 DPIimageType
- the type of image to returndestination
- controlling visibility of optional content groupsjava.io.IOException
- if the PDF cannot be readpublic void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics) throws java.io.IOException
Read renderPageToGraphics(int, Graphics2D, float, float, RenderDestination)
before using this.
pageIndex
- the zero-based index of the page to be convertedgraphics
- the Graphics2D on which to draw the pagejava.io.IOException
- if the PDF cannot be readpublic void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics, float scale) throws java.io.IOException
Read renderPageToGraphics(int, Graphics2D, float, float, RenderDestination)
before using this.
pageIndex
- the zero-based index of the page to be convertedgraphics
- the Graphics2D on which to draw the pagescale
- the scaling factor, where 1 = 72 DPIjava.io.IOException
- if the PDF cannot be readpublic void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics, float scaleX, float scaleY) throws java.io.IOException
Read renderPageToGraphics(int, Graphics2D, float, float, RenderDestination)
before using this.
pageIndex
- the zero-based index of the page to be convertedgraphics
- the Graphics2D on which to draw the pagescaleX
- the scale to draw the page at for the x-axis, where 1 = 72 DPIscaleY
- the scale to draw the page at for the y-axis, where 1 = 72 DPIjava.io.IOException
- if the PDF cannot be readpublic void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics, float scaleX, float scaleY, RenderDestination destination) throws java.io.IOException
Known problems:
renderImage
methods.pageIndex
- the zero-based index of the page to be convertedgraphics
- the Graphics2D on which to draw the pagescaleX
- the scale to draw the page at for the x-axis, where 1 = 72 DPIscaleY
- the scale to draw the page at for the y-axis, where 1 = 72 DPIdestination
- controlling visibility of optional content groupsjava.io.IOException
- if the PDF cannot be readpublic boolean isGroupEnabled(PDOptionalContentGroup group)
group
- the groupprivate void transform(java.awt.Graphics2D graphics, PDPage page, float scaleX, float scaleY)
private boolean isBitonal(java.awt.Graphics2D graphics)
private java.awt.RenderingHints createDefaultRenderingHints(java.awt.Graphics2D graphics)
protected PageDrawer createPageDrawer(PageDrawerParameters parameters) throws java.io.IOException
java.io.IOException
private boolean hasBlendMode(PDPage page)
java.awt.image.BufferedImage getPageImage()
private static void suggestKCMS()
private static boolean isGoodVersion(java.lang.String version, java.lang.String regex, int min)
private static boolean isMinJdk8()