pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1852228 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java
Date Sat, 26 Jan 2019 13:58:40 GMT
Author: tilman
Date: Sat Jan 26 13:58:40 2019
New Revision: 1852228

URL: http://svn.apache.org/viewvc?rev=1852228&view=rev
Log:
PDFBOX-4435: offer subsampling and renderingHints and pass these to PDFPrintable

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java?rev=1852228&r1=1852227&r2=1852228&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java Sat Jan
26 13:58:40 2019
@@ -17,6 +17,7 @@
 
 package org.apache.pdfbox.printing;
 
+import java.awt.RenderingHints;
 import java.awt.print.Book;
 import java.awt.print.PageFormat;
 import java.awt.print.Paper;
@@ -36,6 +37,8 @@ public final class PDFPageable extends B
     private final boolean showPageBorder;
     private final float dpi;
     private final Orientation orientation;
+    private boolean subsamplingAllowed = false;
+    private RenderingHints renderingHints = null;
 
     /**
      * Creates a new PDFPageable.
@@ -89,6 +92,56 @@ public final class PDFPageable extends B
         this.dpi = dpi;
     }
 
+    /**
+     * Get the rendering hints.
+     *
+     * @return the rendering hints or null if none are set.
+     */
+    public RenderingHints getRenderingHints()
+    {
+        return 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 <b><u>at runtime</u></b>
depending on the
+     * destination.
+     *
+     * @param renderingHints
+     */
+    public void setRenderingHints(RenderingHints renderingHints)
+    {
+        this.renderingHints = renderingHints;
+    }
+
+    /**
+     * 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 getNumberOfPages()
     {
@@ -162,6 +215,9 @@ public final class PDFPageable extends B
         {
             throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages());
         }
-        return new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder, dpi);
+        PDFPrintable printable = new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder,
dpi);
+        printable.setSubsamplingAllowed(subsamplingAllowed);
+        printable.setRenderingHints(renderingHints);
+        return printable;
     }
 }



Mime
View raw message