PDFBox:如何防止PDF页面在打印前自动旋转?
问题描述:
我正在尝试使用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();
谢谢。
答
你可以通过Orientation
枚举PDFPageable
构造:
job.setPageable(new PDFPageable(document, Orientation.PORTRAIT));
由于您使用非标准的纸,Orientation.AUTO
默认方向值为解释短边的顶部和底部。
我收到一个错误。它说没有setPageable(arg1,arg2)这样的函数; – Spongebob
是的,你把它传递给PDFPageable的构造函数 - 现在修复的代码 – diginoise
我试过了,但问题仍然存在。 – Spongebob