Description
I try to print a PDF using the following code
// aDevice is the printer device Name // aData is a byte array of my PDF (stored on a DB) .... vPrintService = this.getPrintService(aDevice); vPrinterJob = java.awt.print.PrinterJob.getPrinterJob(); vPrinterJob.setPrintService(vPrintService); vPDDocument = this.getPDDocument(aData); vPDDocument.silentPrint(vPrinterJob); --
public PrintService getPrintService(String aDevice) throws Exception { javax.print.PrintService[] vPrintServices = java.awt.print.PrinterJob.lookupPrintServices(); boolean printerFound = false; for(int i = 0; i < vPrintServices.length; i++) { if(vPrintServices[i].getName().trim().equals(aDevice.trim())) return vPrintServices[i]; } return null; } public PDDocument getPDDocument(GenericBean aData) throws Exception { byte[] vPageData = (byte[])aData.getValueAtKey("Byte"); return PDDocument.load( new ByteArrayInputStream(vPageData) ); }
But if my PDF is LANDSCAPE and the printer instead as PORTRAIT as default, PORTRAIT wins and so the report is not well printed.
Checking the code (based on 1.5.0 and also from lateast trunk) for class PDPageable... probably I found the issue.. and I believe that the implementation is not right (at least from my point of view).
Get a look to the getPageFormat method.
As first it get the page format from the job (PrinterJob)
PageFormat format = job.defaultPage();
after it get the (optional) print service from the job (Printer Job)
PrintService service = job.getPrintService(); // can be null
If the printer service is not null and it have LANDSCAPE as orientation.. it force LANDSCAPE as orientation in the page format otherwise it force it as PORTRAIT
But... in my mind, it should get the orientation from the PDF Page.. and not from the printer job / print service.
I can print documents with different orientation on the same printer and also I can have in the same document pages with different orientation.
Of couse I can make same mistake and read the code in the wrong way... (I found this project yesterday....)
Maybe the "findRotation" method on the PDPage should be invoked and "checked".. or something else....
It this a bug on PDFBox ?
thanks
Roberto
Attachments
Issue Links
- is related to
-
PDFBOX-1138 Printing fails for pages in landscape format
- Closed
- relates to
-
PDFBOX-1448 Printing based on the document orientation
- Closed