[
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.