Package org.apache.pdfbox.printing
Class PDFPrintable
java.lang.Object
org.apache.pdfbox.printing.PDFPrintable
- All Implemented Interfaces:
Printable
Prints pages from a PDF document using any page size or scaling mode.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final float
private final PDPageTree
private final PDFRenderer
private RenderingHints
private final Scaling
private final boolean
private boolean
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
-
Constructor Summary
ConstructorsConstructorDescriptionPDFPrintable
(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
Modifier and TypeMethodDescriptionGet the rendering hints.(package private) static PDRectangle
getRotatedCropBox
(PDPage page) This will find the CropBox with rotation applied, for this page by looking up the hierarchy until it finds them.(package private) static PDRectangle
getRotatedMediaBox
(PDPage page) This will find the MediaBox with rotation applied, for this page by looking up the hierarchy until it finds them.boolean
Value indicating if the renderer is allowed to subsample images before drawing, according to image dimensions and requested scale.int
print
(Graphics graphics, PageFormat pageFormat, int pageIndex) void
setRenderingHints
(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.
-
Field Details
-
pageTree
-
renderer
-
showPageBorder
private final boolean showPageBorder -
scaling
-
dpi
private final float dpi -
center
private final boolean center -
subsamplingAllowed
private boolean subsamplingAllowed -
renderingHints
-
-
Constructor Details
-
PDFPrintable
Creates a new PDFPrintable.- Parameters:
document
- the document to print
-
PDFPrintable
Creates a new PDFPrintable with the given page scaling.- Parameters:
document
- the document to printscaling
- page scaling policy
-
PDFPrintable
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
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 non-zero then the image will be rasterized at the given DPI
-
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 non-zero then the image will be rasterized at the given DPIcenter
- 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 non-zero then the image will be rasterized at the given DPIcenter
- true if the content is to be centered on the page (otherwise top-left).renderer
- the document renderer. Useful ifPDFRenderer
has been subclassed.
-
-
Method Details
-
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
Get the rendering hints.- Returns:
- the rendering hints or null if none are set.
-
setRenderingHints
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
- Specified by:
print
in interfacePrintable
- Throws:
PrinterException
-
getRotatedCropBox
This will find the CropBox with rotation applied, for this page by looking up the hierarchy until it finds them.- Returns:
- The CropBox at this level in the hierarchy.
-
getRotatedMediaBox
This will find the MediaBox with rotation applied, for this page by looking up the hierarchy until it finds them.- Returns:
- The MediaBox at this level in the hierarchy.
-