You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Christophe Borivant (JIRA)" <ji...@apache.org> on 2010/08/05 15:55:16 UTC

[jira] Created: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

PrintPDF does not take the windows default printer orientation into account
---------------------------------------------------------------------------

                 Key: PDFBOX-788
                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
             Project: PDFBox
          Issue Type: Bug
    Affects Versions: 1.2.1
         Environment: Windows XP at least
            Reporter: Christophe Borivant


We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
PrintPDF does not take the default configuration into account.

I wrote a little patch that seems to solve this bug



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting reopened PDFBOX-788:
----------------------------------


Reopening for the reported NPE.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901866#action_12901866 ] 

Jukka Zitting commented on PDFBOX-788:
--------------------------------------

I don't really see the need for a new setter, as the print() method already sets the currentPrinterJob variable. Is there some other need for a client application to set (or get) the printer job?

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901923#action_12901923 ] 

Christophe Borivant commented on PDFBOX-788:
--------------------------------------------

PrinterJob printJob = PrinterJob.getPrinterJob(); 

If I'm not wrong, printJob would only be visible from print method because it is not an instance attribute.
getPageFormat needs to be able to access the original PrintJob to access to the printService and get the printer default configuration.

It's probably possible not to use a setter but it sound like a "best pratice" or a "design pattern" to me (remember I'm not really a developper, but the discussion is interesting ;-) )

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Thomas Chojecki (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12902844#action_12902844 ] 

Thomas Chojecki commented on PDFBOX-788:
----------------------------------------

Got some problems with this patch.

Our Application need to know the PageFormat for some pages. So we called PDDocument.getPageFormat(...)

Now with the changes we got a NPE in Rev 988524 Line 1194

currentPrinterJob is null by default. Hope this will give enought reason for a setter.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved PDFBOX-788.
----------------------------------

         Assignee: Jukka Zitting
    Fix Version/s: 1.3.0
       Resolution: Fixed

Thanks! Patch committed in revision 983627.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christophe Borivant updated PDFBOX-788:
---------------------------------------

    Attachment: PDFBOX-788.diff

Attach the new patch against rev 983635

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christophe Borivant reopened PDFBOX-788:
----------------------------------------


As we added a new instance property, we should have written a new setter ( perhaps a new getter to ).
The caller should be responsible for attaching the PrintJob to the Document.

I also added the name of the job to replace the default "java printing" default job name.
This way you will see something like "PDFBox - document.pdf" in your printer spool.

So here a new patch against rev 983635 ( You can apply it from the root of the trunk ).


> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12904544#action_12904544 ] 

Andreas Lehmkühler commented on PDFBOX-788:
-------------------------------------------

+1, I already had the same idea, but in another context. PDFBOX-586 adresses text extraction on android and the main approach to achieve that seems to split PDFBox in several components and to minimize (in the ong run avoid) the usage of java.awt stuff within the text extraction part. If it comes to printing I'd like to move the affected code into separate classes. In addition to Jukka's proposal we should also move the implementation of the java.awt.print.Printable interface from PDPage to a second class(PDPrintable) or to a new class combining both interfaces.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff, PDPageable.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901883#action_12901883 ] 

Christophe Borivant commented on PDFBOX-788:
--------------------------------------------

It's only a matter of view.
I think the caller, PrintPDF in our case, should be responsible of the PrintJob instantiation.
The caller needs to tell the document: "print yourself on this printer with this jobname".
This way the caller knows the PrintJob and has full control on it.
Especially, one could need to cancel the PrintJob if it is not finished.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christophe Borivant updated PDFBOX-788:
---------------------------------------

    Description: 
We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
PrintPDF does not take the default configuration into account.

I wrote a little patch that seems to solve this bug

here the patch content as I don't know how to attach a file :

--- PDDocument.java   2010-08-05 15:47:53.848113201 +0200
+++ PDDocument.java.new 2010-08-05 15:45:16.805943182 +0200
@@ -23,6 +23,11 @@
 import java.awt.print.Printable;
 import java.awt.print.PrinterException;
 import java.awt.print.PrinterJob;
+
+import javax.print.PrintService;
+import javax.print.attribute.standard.Media;
+import javax.print.attribute.standard.OrientationRequested;
+
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -116,6 +121,8 @@
      */
     private boolean allSecurityToBeRemoved = false;
 
+    private PrinterJob currentPrinterJob = null;
+
     /**
      * Constructor, creates a new PDF Document with no pages.  You need to add
      * at least one page for the document to be valid.
@@ -951,6 +958,9 @@
         PDPage page = (PDPage)getDocumentCatalog().getAllPages().get( pageIndex );
         Dimension mediaBox = page.findMediaBox().createDimension();
         Dimension cropBox = page.findCropBox().createDimension();
+        PrintService printService = currentPrinterJob.getPrintService();
+        Object ob = printService.getDefaultAttributeValue(OrientationRequested.class);
+
         double diffWidth = 0;
         double diffHeight = 0;
         double mediaWidth = mediaBox.getWidth();
@@ -963,13 +973,25 @@
             diffWidth = (mediaWidth - cropWidth)/2;
             diffHeight = (mediaHeight - cropHeight)/2;
         }
-        Paper paper = new Paper();
-        paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
-        paper.setSize( mediaWidth, mediaHeight );
-        PageFormat format = new PageFormat();
+        PageFormat format = currentPrinterJob.defaultPage();
+        Paper paper = format.getPaper();
+
+        if ( "landscape" == ob.toString() )
+        {
+           format.setOrientation(PageFormat.LANDSCAPE);
+           paper.setImageableArea( diffHeight, diffWidth, cropHeight, cropWidth);
+           paper.setSize( mediaHeight, mediaWidth );
+        }
+        else
+        {
+           format.setOrientation(PageFormat.PORTRAIT);
+           paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
+           paper.setSize( mediaWidth, mediaHeight );
+        }
+
         format.setPaper( paper );
         return format;
-    }
+    } 
 
     /**
      * {@inheritDoc}
@@ -1000,6 +1022,7 @@
             throw new PrinterException( "You do not have permission to print this document." );
         }
         printJob.setPageable(this);
+  currentPrinterJob=printJob;
         if( printJob.printDialog() )
         {
             printJob.print();
@@ -1058,6 +1081,7 @@
             throw new PrinterException( "You do not have permission to print this document." );
         }
         printJob.setPageable(this);
+  currentPrinterJob=printJob;
         printJob.print();
     }


  was:
We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
PrintPDF does not take the default configuration into account.

I wrote a little patch that seems to solve this bug




Add the patch content

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug
> here the patch content as I don't know how to attach a file :
> --- PDDocument.java   2010-08-05 15:47:53.848113201 +0200
> +++ PDDocument.java.new 2010-08-05 15:45:16.805943182 +0200
> @@ -23,6 +23,11 @@
>  import java.awt.print.Printable;
>  import java.awt.print.PrinterException;
>  import java.awt.print.PrinterJob;
> +
> +import javax.print.PrintService;
> +import javax.print.attribute.standard.Media;
> +import javax.print.attribute.standard.OrientationRequested;
> +
>  import java.io.BufferedInputStream;
>  import java.io.File;
>  import java.io.FileInputStream;
> @@ -116,6 +121,8 @@
>       */
>      private boolean allSecurityToBeRemoved = false;
>  
> +    private PrinterJob currentPrinterJob = null;
> +
>      /**
>       * Constructor, creates a new PDF Document with no pages.  You need to add
>       * at least one page for the document to be valid.
> @@ -951,6 +958,9 @@
>          PDPage page = (PDPage)getDocumentCatalog().getAllPages().get( pageIndex );
>          Dimension mediaBox = page.findMediaBox().createDimension();
>          Dimension cropBox = page.findCropBox().createDimension();
> +        PrintService printService = currentPrinterJob.getPrintService();
> +        Object ob = printService.getDefaultAttributeValue(OrientationRequested.class);
> +
>          double diffWidth = 0;
>          double diffHeight = 0;
>          double mediaWidth = mediaBox.getWidth();
> @@ -963,13 +973,25 @@
>              diffWidth = (mediaWidth - cropWidth)/2;
>              diffHeight = (mediaHeight - cropHeight)/2;
>          }
> -        Paper paper = new Paper();
> -        paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
> -        paper.setSize( mediaWidth, mediaHeight );
> -        PageFormat format = new PageFormat();
> +        PageFormat format = currentPrinterJob.defaultPage();
> +        Paper paper = format.getPaper();
> +
> +        if ( "landscape" == ob.toString() )
> +        {
> +           format.setOrientation(PageFormat.LANDSCAPE);
> +           paper.setImageableArea( diffHeight, diffWidth, cropHeight, cropWidth);
> +           paper.setSize( mediaHeight, mediaWidth );
> +        }
> +        else
> +        {
> +           format.setOrientation(PageFormat.PORTRAIT);
> +           paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
> +           paper.setSize( mediaWidth, mediaHeight );
> +        }
> +
>          format.setPaper( paper );
>          return format;
> -    }
> +    } 
>  
>      /**
>       * {@inheritDoc}
> @@ -1000,6 +1022,7 @@
>              throw new PrinterException( "You do not have permission to print this document." );
>          }
>          printJob.setPageable(this);
> +  currentPrinterJob=printJob;
>          if( printJob.printDialog() )
>          {
>              printJob.print();
> @@ -1058,6 +1081,7 @@
>              throw new PrinterException( "You do not have permission to print this document." );
>          }
>          printJob.setPageable(this);
> +  currentPrinterJob=printJob;
>          printJob.print();
>      }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christophe Borivant updated PDFBOX-788:
---------------------------------------

    Attachment: PDDocument.patch

Add the patch file

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>         Attachments: PDDocument.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug
> here the patch content as I don't know how to attach a file :
> --- PDDocument.java   2010-08-05 15:47:53.848113201 +0200
> +++ PDDocument.java.new 2010-08-05 15:45:16.805943182 +0200
> @@ -23,6 +23,11 @@
>  import java.awt.print.Printable;
>  import java.awt.print.PrinterException;
>  import java.awt.print.PrinterJob;
> +
> +import javax.print.PrintService;
> +import javax.print.attribute.standard.Media;
> +import javax.print.attribute.standard.OrientationRequested;
> +
>  import java.io.BufferedInputStream;
>  import java.io.File;
>  import java.io.FileInputStream;
> @@ -116,6 +121,8 @@
>       */
>      private boolean allSecurityToBeRemoved = false;
>  
> +    private PrinterJob currentPrinterJob = null;
> +
>      /**
>       * Constructor, creates a new PDF Document with no pages.  You need to add
>       * at least one page for the document to be valid.
> @@ -951,6 +958,9 @@
>          PDPage page = (PDPage)getDocumentCatalog().getAllPages().get( pageIndex );
>          Dimension mediaBox = page.findMediaBox().createDimension();
>          Dimension cropBox = page.findCropBox().createDimension();
> +        PrintService printService = currentPrinterJob.getPrintService();
> +        Object ob = printService.getDefaultAttributeValue(OrientationRequested.class);
> +
>          double diffWidth = 0;
>          double diffHeight = 0;
>          double mediaWidth = mediaBox.getWidth();
> @@ -963,13 +973,25 @@
>              diffWidth = (mediaWidth - cropWidth)/2;
>              diffHeight = (mediaHeight - cropHeight)/2;
>          }
> -        Paper paper = new Paper();
> -        paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
> -        paper.setSize( mediaWidth, mediaHeight );
> -        PageFormat format = new PageFormat();
> +        PageFormat format = currentPrinterJob.defaultPage();
> +        Paper paper = format.getPaper();
> +
> +        if ( "landscape" == ob.toString() )
> +        {
> +           format.setOrientation(PageFormat.LANDSCAPE);
> +           paper.setImageableArea( diffHeight, diffWidth, cropHeight, cropWidth);
> +           paper.setSize( mediaHeight, mediaWidth );
> +        }
> +        else
> +        {
> +           format.setOrientation(PageFormat.PORTRAIT);
> +           paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
> +           paper.setSize( mediaWidth, mediaHeight );
> +        }
> +
>          format.setPaper( paper );
>          return format;
> -    }
> +    } 
>  
>      /**
>       * {@inheritDoc}
> @@ -1000,6 +1022,7 @@
>              throw new PrinterException( "You do not have permission to print this document." );
>          }
>          printJob.setPageable(this);
> +  currentPrinterJob=printJob;
>          if( printJob.printDialog() )
>          {
>              printJob.print();
> @@ -1058,6 +1081,7 @@
>              throw new PrinterException( "You do not have permission to print this document." );
>          }
>          printJob.setPageable(this);
> +  currentPrinterJob=printJob;
>          printJob.print();
>      }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901940#action_12901940 ] 

Jukka Zitting commented on PDFBOX-788:
--------------------------------------

The currentPrinterJob variable is mostly an internal implementation detail that's only accessed during the print() method. It needs to be an instance variable instead of a local method variable because otherwise the getPageFormat method can't access it. A more ideal design would probably be to use an inner class for the Pageable implementation instead of implementing the interface directly in PDDocument, but since that would break backwards-compatibility we need to keep the currentPrinterJob as an instance variable of PDDocument.

To summarize, there isn't really any need for anyone outside the PDDocument class to access the currentPrinterJob variable, so to maintain proper encapsulation of implementation details it's best not to expose it through a setter or a getter.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved PDFBOX-788.
----------------------------------

    Resolution: Fixed

Exactly, resolving as fixed.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christophe Borivant updated PDFBOX-788:
---------------------------------------

    Description: 
We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
PrintPDF does not take the default configuration into account.

I wrote a little patch that seems to solve this bug


  was:
We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
PrintPDF does not take the default configuration into account.

I wrote a little patch that seems to solve this bug

here the patch content as I don't know how to attach a file :

--- PDDocument.java   2010-08-05 15:47:53.848113201 +0200
+++ PDDocument.java.new 2010-08-05 15:45:16.805943182 +0200
@@ -23,6 +23,11 @@
 import java.awt.print.Printable;
 import java.awt.print.PrinterException;
 import java.awt.print.PrinterJob;
+
+import javax.print.PrintService;
+import javax.print.attribute.standard.Media;
+import javax.print.attribute.standard.OrientationRequested;
+
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -116,6 +121,8 @@
      */
     private boolean allSecurityToBeRemoved = false;
 
+    private PrinterJob currentPrinterJob = null;
+
     /**
      * Constructor, creates a new PDF Document with no pages.  You need to add
      * at least one page for the document to be valid.
@@ -951,6 +958,9 @@
         PDPage page = (PDPage)getDocumentCatalog().getAllPages().get( pageIndex );
         Dimension mediaBox = page.findMediaBox().createDimension();
         Dimension cropBox = page.findCropBox().createDimension();
+        PrintService printService = currentPrinterJob.getPrintService();
+        Object ob = printService.getDefaultAttributeValue(OrientationRequested.class);
+
         double diffWidth = 0;
         double diffHeight = 0;
         double mediaWidth = mediaBox.getWidth();
@@ -963,13 +973,25 @@
             diffWidth = (mediaWidth - cropWidth)/2;
             diffHeight = (mediaHeight - cropHeight)/2;
         }
-        Paper paper = new Paper();
-        paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
-        paper.setSize( mediaWidth, mediaHeight );
-        PageFormat format = new PageFormat();
+        PageFormat format = currentPrinterJob.defaultPage();
+        Paper paper = format.getPaper();
+
+        if ( "landscape" == ob.toString() )
+        {
+           format.setOrientation(PageFormat.LANDSCAPE);
+           paper.setImageableArea( diffHeight, diffWidth, cropHeight, cropWidth);
+           paper.setSize( mediaHeight, mediaWidth );
+        }
+        else
+        {
+           format.setOrientation(PageFormat.PORTRAIT);
+           paper.setImageableArea( diffWidth, diffHeight, cropWidth, cropHeight);
+           paper.setSize( mediaWidth, mediaHeight );
+        }
+
         format.setPaper( paper );
         return format;
-    }
+    } 
 
     /**
      * {@inheritDoc}
@@ -1000,6 +1022,7 @@
             throw new PrinterException( "You do not have permission to print this document." );
         }
         printJob.setPageable(this);
+  currentPrinterJob=printJob;
         if( printJob.printDialog() )
         {
             printJob.print();
@@ -1058,6 +1081,7 @@
             throw new PrinterException( "You do not have permission to print this document." );
         }
         printJob.setPageable(this);
+  currentPrinterJob=printJob;
         printJob.print();
     }



Removed the patch content from the description as the patch file has been attached

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>         Attachments: PDDocument.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved PDFBOX-788.
----------------------------------

    Resolution: Fixed

I committed the proposed patch in revision 992282 and extended it to cover Andreas' idea in revision 992284.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff, PDPageable.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901887#action_12901887 ] 

Jukka Zitting commented on PDFBOX-788:
--------------------------------------

> I think the caller, PrintPDF in our case, should be responsible of the PrintJob instantiation. 
> The caller needs to tell the document: "print yourself on this printer with this jobname".

Isn't that already covered by the PDDocument.print(PrinterJob) method call? The current code in PrintPDF is essentially:

    PrinterJob printJob = PrinterJob.getPrinterJob();
    ...; // configure the printJob
    document.print( printJob );

I'm not sure what extra value a setCurrentPrinterJob() setter would give us here.

PS. In revision 988523 I committed the suggested improvement to explicitly set the print job name. And in revision 988524 I simplified the PDDocument print methods a bit by removing duplicate code.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901945#action_12901945 ] 

Christophe Borivant commented on PDFBOX-788:
--------------------------------------------

Ok, you convince me.
+, if we need a getter or a setter for any reason, it will never be too late to add it.


> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting updated PDFBOX-788:
---------------------------------

    Attachment: PDPageable.patch

The attached patch (PDPageable.patch) addresses the NPE issue in a relatively clean fashion by introducing a new PDPageable adapter class that should be used instead of directly accessing the Pageable methods in PDDocument.

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff, PDPageable.patch
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-788) PrintPDF does not take the windows default printer orientation into account

Posted by "Christophe Borivant (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901947#action_12901947 ] 

Christophe Borivant commented on PDFBOX-788:
--------------------------------------------

The bug should be closed

> PrintPDF does not take the windows default printer orientation into account
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-788
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-788
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.2.1
>         Environment: Windows XP at least
>            Reporter: Christophe Borivant
>            Assignee: Jukka Zitting
>             Fix For: 1.3.0
>
>         Attachments: PDDocument.patch, PDFBOX-788.diff
>
>
> We have 2 printers, the first one is defined to print in Portrait by default in Windows, the other one is defined to print in Landscape by default in Windows.
> PrintPDF does not take the default configuration into account.
> I wrote a little patch that seems to solve this bug

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.