Package org.apache.pdfbox.rendering
Class PDFRenderer
- java.lang.Object
-
- org.apache.pdfbox.rendering.PDFRenderer
-
public class PDFRenderer extends java.lang.Object
Renders a PDF document to an AWT BufferedImage. This class may be overridden in order to perform custom rendering.- Author:
- John Hewson
-
-
Field Summary
Fields Modifier and Type Field Description protected PDDocument
document
-
Constructor Summary
Constructors Constructor Description PDFRenderer(PDDocument document)
Creates a new PDFRenderer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PageDrawer
createPageDrawer(PageDrawerParameters parameters)
Returns a new PageDrawer instance, using the given parameters.AnnotationFilter
getAnnotationsFilter()
Return the AnnotationFilter.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 DPIjava.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
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.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
setAnnotationsFilter(AnnotationFilter annotationsFilter)
Set the AnnotationFilter.void
setSubsamplingAllowed(boolean subsamplingAllowed)
Sets a value instructing the renderer whether it is allowed to subsample images before drawing.
-
-
-
Field Detail
-
document
protected final PDDocument document
-
-
Constructor Detail
-
PDFRenderer
public PDFRenderer(PDDocument document)
Creates a new PDFRenderer.- Parameters:
document
- the document to render
-
-
Method Detail
-
getAnnotationsFilter
public AnnotationFilter getAnnotationsFilter()
Return the AnnotationFilter.- Returns:
- the AnnotationFilter
-
setAnnotationsFilter
public void setAnnotationsFilter(AnnotationFilter annotationsFilter)
Set the AnnotationFilter.Allows to only render annotation accepted by the filter.
- Parameters:
annotationsFilter
- the AnnotationFilter
-
isSubsamplingAllowed
public boolean isSubsamplingAllowed()
Value indicating if the renderer is allowed to subsample images before drawing, according to image dimensions and requested scale. Subsampling may be faster and less memory-intensive in some cases, but it may also lead to loss of quality, especially in images with high spatial frequency.- Returns:
- true if subsampling of images is allowed, false otherwise.
-
setSubsamplingAllowed
public void setSubsamplingAllowed(boolean subsamplingAllowed)
Sets a value instructing the renderer whether it is allowed to subsample images before drawing. The subsampling frequency is determined according to image size and requested scale. Subsampling may be faster and less memory-intensive in some cases, but it may also lead to loss of quality, especially in images with high spatial frequency.- Parameters:
subsamplingAllowed
- The new value indicating if subsampling is allowed.
-
renderImage
public java.awt.image.BufferedImage renderImage(int pageIndex) throws java.io.IOException
Returns the given page as an RGB image at 72 DPI- Parameters:
pageIndex
- the zero-based index of the page to be converted.- Returns:
- the rendered page image
- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderImage
public java.awt.image.BufferedImage renderImage(int pageIndex, float scale) throws java.io.IOException
Returns the given page as an RGB image at the given scale. A scale of 1 will render at 72 DPI.- Parameters:
pageIndex
- the zero-based index of the page to be convertedscale
- the scaling factor, where 1 = 72 DPI- Returns:
- the rendered page image
- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderImageWithDPI
public java.awt.image.BufferedImage renderImageWithDPI(int pageIndex, float dpi) throws java.io.IOException
Returns the given page as an RGB image at the given DPI.- Parameters:
pageIndex
- the zero-based index of the page to be converteddpi
- the DPI (dots per inch) to render at- Returns:
- the rendered page image
- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderImageWithDPI
public java.awt.image.BufferedImage renderImageWithDPI(int pageIndex, float dpi, ImageType imageType) throws java.io.IOException
Returns the given page as an RGB image at the given DPI.- Parameters:
pageIndex
- the zero-based index of the page to be converteddpi
- the DPI (dots per inch) to render atimageType
- the type of image to return- Returns:
- the rendered page image
- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderImage
public java.awt.image.BufferedImage renderImage(int pageIndex, float scale, ImageType imageType) throws java.io.IOException
Returns the given page as an RGB or ARGB image at the given scale.- Parameters:
pageIndex
- the zero-based index of the page to be convertedscale
- the scaling factor, where 1 = 72 DPIimageType
- the type of image to return- Returns:
- the rendered page image
- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderPageToGraphics
public void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics) throws java.io.IOException
Renders a given page to an AWT Graphics2D instance.- Parameters:
pageIndex
- the zero-based index of the page to be convertedgraphics
- the Graphics2D on which to draw the page- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderPageToGraphics
public void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics, float scale) throws java.io.IOException
Renders a given page to an AWT Graphics2D instance.- Parameters:
pageIndex
- the zero-based index of the page to be convertedgraphics
- the Graphics2D on which to draw the pagescale
- the scale to draw the page at- Throws:
java.io.IOException
- if the PDF cannot be read
-
renderPageToGraphics
public void renderPageToGraphics(int pageIndex, java.awt.Graphics2D graphics, float scaleX, float scaleY) throws java.io.IOException
Renders a given page to an AWT Graphics2D instance.- Parameters:
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-axisscaleY
- the scale to draw the page at for the y-axis- Throws:
java.io.IOException
- if the PDF cannot be read
-
createPageDrawer
protected PageDrawer createPageDrawer(PageDrawerParameters parameters) throws java.io.IOException
Returns a new PageDrawer instance, using the given parameters. May be overridden.- Throws:
java.io.IOException
-
-