pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1852219 - /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java
Date Sat, 26 Jan 2019 12:00:30 GMT
Author: tilman
Date: Sat Jan 26 12:00:30 2019
New Revision: 1852219

URL: http://svn.apache.org/viewvc?rev=1852219&view=rev
Log:
PDFBOX-4435: add new option for PrintPDF command line utility

Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java?rev=1852219&r1=1852218&r2=1852219&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java Sat Jan 26 12:00:30
2019
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.tools;
 
+import java.awt.RenderingHints;
 import java.awt.print.PrinterException;
 import java.awt.print.PrinterJob;
 import java.io.File;
@@ -27,6 +28,8 @@ import javax.print.PrintService;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.printing.Orientation;
 import org.apache.pdfbox.printing.PDFPageable;
+import org.apache.pdfbox.printing.PDFPrintable;
+import org.apache.pdfbox.printing.Scaling;
 
 /**
  * This is a command line program that will print a PDF document.
@@ -41,6 +44,7 @@ public final class PrintPDF
     private static final String ORIENTATION = "-orientation";
     private static final String BORDER = "-border";
     private static final String DPI = "-dpi";
+    private static final String NOCOLOROPT = "-noColorOpt";
 
     /**
      * private constructor.
@@ -73,6 +77,8 @@ public final class PrintPDF
         orientationMap.put("auto", Orientation.AUTO);
         orientationMap.put("landscape", Orientation.LANDSCAPE);
         orientationMap.put("portrait", Orientation.PORTRAIT);
+        RenderingHints renderingHints = null;
+
         for (int i = 0; i < args.length; i++)
         {
             switch (args[i])
@@ -119,6 +125,15 @@ public final class PrintPDF
                     }
                     dpi = Integer.parseInt(args[i]);
                     break;
+                case NOCOLOROPT:
+                    renderingHints = new RenderingHints(null);
+                    renderingHints.put(RenderingHints.KEY_INTERPOLATION,
+                                       RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+                    renderingHints.put(RenderingHints.KEY_RENDERING,
+                                       RenderingHints.VALUE_RENDER_QUALITY);
+                    renderingHints.put(RenderingHints.KEY_ANTIALIASING,
+                                       RenderingHints.VALUE_ANTIALIAS_OFF);
+                    break;
                 default:
                     pdfFile = args[i];
                     break;
@@ -149,7 +164,10 @@ public final class PrintPDF
                 }
             }
             printJob.setPageable(new PDFPageable(document, orientation, showPageBorder, dpi));
-            
+            PDFPrintable printable = new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder,
dpi);
+            printable.setRenderingHints(renderingHints);
+            printJob.setPrintable(printable);
+
             if (silentPrint || printJob.printDialog())
             {
                 printJob.print();
@@ -171,6 +189,8 @@ public final class PrintPDF
                 + "  -border                              : Print with border\n"
                 + "  -dpi                                 : Render into intermediate image
with\n"
                 + "                                           specific dpi and then print\n"
+                + "  -noColorOpt                          : Disable color optimizations\n"
+                + "                                           (useful when printing barcodes)\n"
                 + "  -silentPrint                         : Print without printer dialog
box\n";
         
         System.err.println(message);



Mime
View raw message