You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/03/28 16:30:30 UTC
svn commit: r1827929 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
Author: tilman
Date: Wed Mar 28 16:30:30 2018
New Revision: 1827929
URL: http://svn.apache.org/viewvc?rev=1827929&view=rev
Log:
PDFBOX-4169: allow to set subsampling, as suggested by Marek Pribula
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java?rev=1827929&r1=1827928&r2=1827929&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java Wed Mar 28 16:30:30 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