pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1602322 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFPrinter.java
Date Fri, 13 Jun 2014 01:49:43 GMT
Author: jahewson
Date: Fri Jun 13 01:49:43 2014
New Revision: 1602322

URL: http://svn.apache.org/r1602322
Log:
PDFBOX-2094: Allow PrintRequestAttributeSet to be passed to printDialog()

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFPrinter.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFPrinter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFPrinter.java?rev=1602322&r1=1602321&r2=1602322&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFPrinter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFPrinter.java Fri Jun
13 01:49:43 2014
@@ -22,6 +22,7 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.rendering.printing.Orientation;
 import org.apache.pdfbox.rendering.printing.Scaling;
 
+import javax.print.attribute.PrintRequestAttributeSet;
 import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -172,7 +173,7 @@ public class PDFPrinter
      */
     public void silentPrint(PrinterJob printerJob) throws PrinterException
     {
-        print(printerJob, true);
+        print(printerJob, null, true);
     }
 
     /**
@@ -181,33 +182,55 @@ public class PDFPrinter
      * This is a convenience method to create the java.awt.print.PrinterJob.
      * Advanced printing tasks can be performed using {@link #getPageable()} instead.
      *
+     * @return true if the user does not cancel the dialog
      * @throws PrinterException if the document cannot be printed
      */
-    public void print() throws PrinterException
+    public boolean print() throws PrinterException
     {
-        print(printerJob);
+        return print(printerJob);
+    }
+
+    /**
+     * Prints the given document using the default printer without prompting the user.
+     * The image is generated using {@link PageDrawer}.
+     * This is a convenience method to create the java.awt.print.PrinterJob.
+     * Advanced printing tasks can be performed using {@link #getPageable()} instead.
+     *
+     * @param attributes application supplied attributes
+     * @return true if the user does not cancel the dialog
+     * @throws PrinterException if the document cannot be printed
+     */
+    public boolean print(PrintRequestAttributeSet attributes) throws PrinterException
+    {
+        return print(printerJob, attributes);
     }
 
     /**
      * Prints the given document using the default printer without prompting the user.
      * @param printerJob the printer job.
+     * @return true if the user does not cancel the dialog
      * @throws PrinterException if the document cannot be printed
      */
-    public void print(PrinterJob printerJob) throws PrinterException
+    public boolean print(PrinterJob printerJob) throws PrinterException
     {
-        print(printerJob, false);
+        return print(printerJob, null, false);
     }
 
     /**
-     * Returns the Pageable instance used in this class. Can be overridden by subclasses.
+     * Prints the given document using the default printer without prompting the user.
+     * @param printerJob the printer job.
+     * @param attributes application supplied attributes
+     * @return true if the user does not cancel the dialog
+     * @throws PrinterException if the document cannot be printed
      */
-    public PDFPageable getPageable()
+    public boolean print(PrinterJob printerJob, PrintRequestAttributeSet attributes) throws
PrinterException
     {
-        return new PDFPageable();
+        return print(printerJob, attributes, false);
     }
 
     // prints a document
-    private void print(PrinterJob job, boolean isSilent) throws PrinterException
+    private boolean print(PrinterJob job, PrintRequestAttributeSet attributes, boolean isSilent)
+        throws PrinterException
     {
         if (job == null)
         {
@@ -216,11 +239,37 @@ public class PDFPrinter
         else
         {
             job.setPageable(getPageable());
-            if (isSilent || job.printDialog())
+            if (isSilent)
             {
                 job.print();
+                return true;
+            }
+            else if (attributes == null)
+            {
+                if (job.printDialog())
+                {
+                    job.print();
+                    return true;
+                }
+            }
+            else
+            {
+                if (job.printDialog(attributes))
+                {
+                    job.print();
+                    return true;
+                }
             }
         }
+        return false;
+    }
+
+    /**
+     * Returns the Pageable instance used in this class. Can be overridden by subclasses.
+     */
+    public PDFPageable getPageable()
+    {
+      return new PDFPageable();
     }
 
     protected class PDFPageable implements Pageable



Mime
View raw message