pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r992284 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: PDPage.java PDPageable.java
Date Fri, 03 Sep 2010 13:03:50 GMT
Author: jukka
Date: Fri Sep  3 13:03:50 2010
New Revision: 992284

URL: http://svn.apache.org/viewvc?rev=992284&view=rev
Log:
PDFBOX-788: PrintPDF does not take the windows default printer orientation into account

Make the PDPageable adapter implement also the Printable interface.

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java?rev=992284&r1=992283&r2=992284&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java Fri Sep  3 13:03:50
2010
@@ -54,6 +54,10 @@ import java.util.List;
 
 /**
  * This represents a single page in a PDF document.
+ * <p>
+ * This class implements the {@link Printable} interface, but since PDFBox
+ * version 1.3.0 you should be using the {@link PDPageable} adapter instead
+ * (see <a href="https://issues.apache.org/jira/browse/PDFBOX-788">PDFBOX-788</a>).
  *
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.29 $
@@ -808,23 +812,22 @@ public class PDPage implements COSObject
     }
 
     /**
-     * {@inheritDoc}
+     * @deprecated Use the {@link PDPageable} adapter class
      */
     public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
         throws PrinterException
     {
-        int retval = Printable.PAGE_EXISTS;
         try
         {
             PageDrawer drawer = new PageDrawer();
             PDRectangle cropBox = findCropBox();
             drawer.drawPage( graphics, this, cropBox.createDimension() );
+            return PAGE_EXISTS;
         }
         catch( IOException io )
         {
             throw new PrinterIOException( io );
         }
-        return retval;
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java?rev=992284&r1=992283&r2=992284&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java Fri Sep  3
13:03:50 2010
@@ -19,6 +19,7 @@ package org.apache.pdfbox.pdmodel;
 import static javax.print.attribute.standard.OrientationRequested.LANDSCAPE;
 
 import java.awt.Dimension;
+import java.awt.Graphics;
 import java.awt.print.PageFormat;
 import java.awt.print.Pageable;
 import java.awt.print.Paper;
@@ -32,15 +33,15 @@ import javax.print.PrintService;
 import javax.print.attribute.standard.OrientationRequested;
 
 /**
- * Adapter class that implements the {@link Pageable} interface for
- * printing a given PDF document. Note that the given PDF document should
- * not be modified (pages added, removed, etc.) while an instance of this
- * class is being used.
+ * Adapter class that implements the {@link Pageable} and {@link Printable}
+ * interfaces for printing a given PDF document. Note that the given PDF
+ * document should not be modified (pages added, removed, etc.) while an
+ * instance of this class is being used.
  *
  * @since Apache PDFBox 1.3.0
  * @see <a href="https://issues.apache.org/jira/browse/PDFBOX-788">PDFBOX-788</a>
  */
-public class PDPageable implements Pageable {
+public class PDPageable implements Pageable, Printable {
 
     /**
      * List of all pages in the given PDF document.
@@ -164,4 +165,26 @@ public class PDPageable implements Pagea
         return pages.get(i);
     }
 
+    //-----------------------------------------------------------< Printable >
+
+    /**
+     * Prints the page at the given index.
+     *
+     * @param graphics printing target
+     * @param format page format
+     * @param i page index, zero-based
+     * @return {@link Printable#PAGE_EXISTS} if the page was printed,
+     *         or {@link Printable#NO_SUCH_PAGE} if page index was invalid
+     * @throws PrinterException if printing failed
+     */
+    @SuppressWarnings("deprecation")
+    public int print(Graphics graphics, PageFormat format, int i)
+            throws PrinterException {
+        if (0 <= i && i < pages.size()) {
+            return pages.get(i).print(graphics, format, i);
+        } else {
+            return NO_SUCH_PAGE;
+        }
+    }
+
 }



Mime
View raw message