Package org.apache.pdfbox.printing
Class PDFPrintable
- java.lang.Object
-
- org.apache.pdfbox.printing.PDFPrintable
-
- All Implemented Interfaces:
java.awt.print.Printable
public final class PDFPrintable extends java.lang.Object implements java.awt.print.PrintablePrints pages from a PDF document using any page size or scaling mode.- Author:
- John Hewson
-
-
Field Summary
Fields Modifier and Type Field Description static floatRASTERIZE_DPI_AUTOstatic floatRASTERIZE_OFF
-
Constructor Summary
Constructors Constructor Description PDFPrintable(PDDocument document)Creates a new PDFPrintable.PDFPrintable(PDDocument document, Scaling scaling)Creates a new PDFPrintable with the given page scaling.PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder)Creates a new PDFPrintable with the given page scaling and with optional page borders shown.PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi)Creates a new PDFPrintable with the given page scaling and with optional page borders shown.PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi, boolean center)Creates a new PDFPrintable with the given page scaling and with optional page borders shown.PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi, boolean center, PDFRenderer renderer)Creates a new PDFPrintable with the given page scaling and with optional page borders shown.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.RenderingHintsgetRenderingHints()Get the rendering hints.booleanisSubsamplingAllowed()Value indicating if the renderer is allowed to subsample images before drawing, according to image dimensions and requested scale.intprint(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)voidsetRenderingHints(java.awt.RenderingHints renderingHints)Set the rendering hints.voidsetSubsamplingAllowed(boolean subsamplingAllowed)Sets a value instructing the renderer whether it is allowed to subsample images before drawing.
-
-
-
Field Detail
-
RASTERIZE_OFF
public static final float RASTERIZE_OFF
- See Also:
- Constant Field Values
-
RASTERIZE_DPI_AUTO
public static final float RASTERIZE_DPI_AUTO
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PDFPrintable
public PDFPrintable(PDDocument document)
Creates a new PDFPrintable.- Parameters:
document- the document to print
-
PDFPrintable
public PDFPrintable(PDDocument document, Scaling scaling)
Creates a new PDFPrintable with the given page scaling.- Parameters:
document- the document to printscaling- page scaling policy
-
PDFPrintable
public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder)
Creates a new PDFPrintable with the given page scaling and with optional page borders shown.- Parameters:
document- the document to printscaling- page scaling policyshowPageBorder- true if page borders are to be printed
-
PDFPrintable
public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi)
Creates a new PDFPrintable with the given page scaling and with optional page borders shown. The image will be rasterized at the given DPI before being sent to the printer.- Parameters:
document- the document to printscaling- page scaling policyshowPageBorder- true if page borders are to be printeddpi- if positive non-zero then the image will be rasterized at the given DPI. If set to the special value RASTERIZE_DPI_AUTO, the dpi of the printer will be used.
-
PDFPrintable
public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi, boolean center)
Creates a new PDFPrintable with the given page scaling and with optional page borders shown. The image will be rasterized at the given DPI before being sent to the printer.- Parameters:
document- the document to printscaling- page scaling policyshowPageBorder- true if page borders are to be printeddpi- if positive non-zero then the image will be rasterized at the given DPI. If set to the special value RASTERIZE_DPI_AUTO, the dpi of the printer will be used.center- true if the content is to be centered on the page (otherwise top-left).
-
PDFPrintable
public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi, boolean center, PDFRenderer renderer)
Creates a new PDFPrintable with the given page scaling and with optional page borders shown. The image will be rasterized at the given DPI before being sent to the printer.- Parameters:
document- the document to printscaling- page scaling policyshowPageBorder- true if page borders are to be printeddpi- if positive non-zero then the image will be rasterized at the given DPI. If set to the special value RASTERIZE_DPI_AUTO, the dpi of the printer will be used.center- true if the content is to be centered on the page (otherwise top-left).renderer- the document renderer. Useful ifPDFRendererhas been subclassed.
-
-
Method Detail
-
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.
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
Get the rendering hints.- Returns:
- the rendering hints or null if none are set.
-
setRenderingHints
public void setRenderingHints(java.awt.RenderingHints renderingHints)
Set the rendering hints. Use this to influence rendering quality and speed. If you don't set them yourself or pass null, PDFBox will decide at runtime depending on the destination.- Parameters:
renderingHints-
-
print
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException- Specified by:
printin interfacejava.awt.print.Printable- Throws:
java.awt.print.PrinterException
-
-