2017-05-26 432 views
0

我正在嘗試使用PDFbox庫打印PDF。但最終的印刷品旋轉了90度。頁面尺寸爲70毫米x 17毫米,但打印長度爲17毫米x 70毫米。PDFBox:如何防止PDF頁面在打印前自動旋轉?

String filename = dest; 
    PDDocument document = PDDocument.load(new File (filename)); 

    PrintService myPrintService = PrintServiceLookup.lookupDefaultPrintService(); 
    PrinterJob job = PrinterJob.getPrinterJob(); 
    job.setPageable(new PDFPageable(document)); 
    job.setPrintService(myPrintService); 
    if(job.printDialog()) 
     job.print(); 
    document.close(); 

謝謝。

回答

0

你可以通過Orientation枚舉PDFPageable構造:

job.setPageable(new PDFPageable(document, Orientation.PORTRAIT)); 

由於您使用非標準的紙,Orientation.AUTO默認方向值爲解釋短邊的頂部和底部。

+0

我收到一個錯誤。它說沒有setPageable(arg1,arg2)這樣的函數; – Spongebob

+0

是的,你把它傳遞給PDFPageable的構造函數 - 現在修復的代碼 – diginoise

+0

我試過了,但問題仍然存在。 – Spongebob