PDFBox:如何防止pdf页面在打印前自动旋转?

时间:2017-05-26 15:08:27

标签: java pdf printing pdfbox

我正在尝试使用PDFbox库打印PDF。但是合成的印刷品旋转了90度。页面尺寸为70mm x 17mm,但打印长度为17mm x 70mm。

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();

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以将Orientation枚举传递给PDFPageable构造函数:

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

由于您使用的是非标准纸张,因此Orientation.AUTO的默认方向值是将较短边缘解释为顶部和底部。