PDFPrintable.java (pdfbox-2.0.23-src) | : | PDFPrintable.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
import java.awt.RenderingHints; | import java.awt.RenderingHints; | |||
import java.awt.geom.AffineTransform; | import java.awt.geom.AffineTransform; | |||
import java.awt.image.BufferedImage; | import java.awt.image.BufferedImage; | |||
import java.awt.print.PageFormat; | import java.awt.print.PageFormat; | |||
import java.awt.print.Printable; | import java.awt.print.Printable; | |||
import java.awt.print.PrinterException; | import java.awt.print.PrinterException; | |||
import java.awt.print.PrinterIOException; | import java.awt.print.PrinterIOException; | |||
import java.io.IOException; | import java.io.IOException; | |||
import org.apache.pdfbox.pdmodel.PDDocument; | import org.apache.pdfbox.pdmodel.PDDocument; | |||
import org.apache.pdfbox.pdmodel.PDPage; | import org.apache.pdfbox.pdmodel.PDPage; | |||
import org.apache.pdfbox.pdmodel.PDPageTree; | ||||
import org.apache.pdfbox.pdmodel.common.PDRectangle; | import org.apache.pdfbox.pdmodel.common.PDRectangle; | |||
import org.apache.pdfbox.rendering.PDFRenderer; | import org.apache.pdfbox.rendering.PDFRenderer; | |||
import org.apache.pdfbox.rendering.RenderDestination; | import org.apache.pdfbox.rendering.RenderDestination; | |||
/** | /** | |||
* Prints pages from a PDF document using any page size or scaling mode. | * Prints pages from a PDF document using any page size or scaling mode. | |||
* | * | |||
* @author John Hewson | * @author John Hewson | |||
*/ | */ | |||
public final class PDFPrintable implements Printable | public final class PDFPrintable implements Printable | |||
{ | { | |||
private final PDDocument document; | private final PDPageTree pageTree; | |||
private final PDFRenderer renderer; | private final PDFRenderer renderer; | |||
private final boolean showPageBorder; | private final boolean showPageBorder; | |||
private final Scaling scaling; | private final Scaling scaling; | |||
private final float dpi; | private final float dpi; | |||
private final boolean center; | private final boolean center; | |||
private boolean subsamplingAllowed = false; | private boolean subsamplingAllowed = false; | |||
private RenderingHints renderingHints = null; | private RenderingHints renderingHints = null; | |||
/** | /** | |||
skipping to change at line 132 | skipping to change at line 133 | |||
* @param document the document to print | * @param document the document to print | |||
* @param scaling page scaling policy | * @param scaling page scaling policy | |||
* @param showPageBorder true if page borders are to be printed | * @param showPageBorder true if page borders are to be printed | |||
* @param dpi if non-zero then the image will be rasterized at the given DPI | * @param dpi if non-zero then the image will be rasterized at the given DPI | |||
* @param center true if the content is to be centered on the page (otherwis e top-left). | * @param center true if the content is to be centered on the page (otherwis e top-left). | |||
* @param renderer the document renderer. Useful if {@link PDFRenderer} has been subclassed. | * @param renderer the document renderer. Useful if {@link PDFRenderer} has been subclassed. | |||
*/ | */ | |||
public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBo rder, float dpi, | public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBo rder, float dpi, | |||
boolean center, PDFRenderer renderer) | boolean center, PDFRenderer renderer) | |||
{ | { | |||
this.document = document; | this.pageTree = document.getPages(); | |||
this.renderer = renderer; | this.renderer = renderer; | |||
this.scaling = scaling; | this.scaling = scaling; | |||
this.showPageBorder = showPageBorder; | this.showPageBorder = showPageBorder; | |||
this.dpi = dpi; | this.dpi = dpi; | |||
this.center = center; | this.center = center; | |||
} | } | |||
/** | /** | |||
* Value indicating if the renderer is allowed to subsample images before dr awing, according to | * Value indicating if the renderer is allowed to subsample images before dr awing, according to | |||
* image dimensions and requested scale. | * image dimensions and requested scale. | |||
skipping to change at line 194 | skipping to change at line 195 | |||
*/ | */ | |||
public void setRenderingHints(RenderingHints renderingHints) | public void setRenderingHints(RenderingHints renderingHints) | |||
{ | { | |||
this.renderingHints = renderingHints; | this.renderingHints = renderingHints; | |||
} | } | |||
@Override | @Override | |||
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) | public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) | |||
throws PrinterException | throws PrinterException | |||
{ | { | |||
if (pageIndex < 0 || pageIndex >= document.getNumberOfPages()) | if (pageIndex < 0 || pageIndex >= pageTree.getCount()) | |||
{ | { | |||
return NO_SUCH_PAGE; | return NO_SUCH_PAGE; | |||
} | } | |||
try | try | |||
{ | { | |||
Graphics2D graphics2D = (Graphics2D)graphics; | Graphics2D graphics2D = (Graphics2D)graphics; | |||
PDPage page = document.getPage(pageIndex); | PDPage page = pageTree.get(pageIndex); | |||
PDRectangle cropBox = getRotatedCropBox(page); | PDRectangle cropBox = getRotatedCropBox(page); | |||
// the imageable area is the area within the page margins | // the imageable area is the area within the page margins | |||
final double imageableWidth = pageFormat.getImageableWidth(); | final double imageableWidth = pageFormat.getImageableWidth(); | |||
final double imageableHeight = pageFormat.getImageableHeight(); | final double imageableHeight = pageFormat.getImageableHeight(); | |||
double scale = 1; | double scale = 1; | |||
if (scaling != Scaling.ACTUAL_SIZE) | if (scaling != Scaling.ACTUAL_SIZE) | |||
{ | { | |||
// scale to fit | // scale to fit | |||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 5 lines changed or added |