Author: tilman Date: Wed Mar 28 16:30:34 2018 New Revision: 1827930 URL: http://svn.apache.org/viewvc?rev=1827930&view=rev Log: PDFBOX-4169: allow to set subsampling, as suggested by Marek Pribula
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java?rev=1827930&r1=1827929&r2=1827930&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java Wed Mar 28 16:30:34 2018 @@ -47,6 +47,7 @@ public final class PDFPrintable implemen private final Scaling scaling; private final float dpi; private final boolean center; + private boolean subsamplingAllowed = false; /** * Creates a new PDFPrintable. @@ -115,7 +116,35 @@ public final class PDFPrintable implemen this.dpi = dpi; this.center = center; } - + + /** + * 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. + * + * @return true if subsampling of images is allowed, false otherwise. + */ + public boolean isSubsamplingAllowed() + { + return 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. + * + * @param subsamplingAllowed The new value indicating if subsampling is allowed. + */ + public void setSubsamplingAllowed(boolean subsamplingAllowed) + { + this.subsamplingAllowed = subsamplingAllowed; + } + @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException @@ -187,6 +216,7 @@ public final class PDFPrintable implemen // draw to graphics using PDFRender AffineTransform transform = (AffineTransform)graphics2D.getTransform().clone(); graphics2D.setBackground(Color.WHITE); + renderer.setSubsamplingAllowed(subsamplingAllowed); renderer.renderPageToGraphics(pageIndex, graphics2D, (float)scale); // draw crop box