我需要打印PDF并配置纸张尺寸和方向。 这是我的代码,但属性不起作用。
private void doPrint(){
try{
PDDocument aImprimir = PDDocument.load(new File("./file.pdf")); //org.apache.pdfbox.pdmodel.PDDocument
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(MediaSizeName.ISO_A8);
attributes.add(OrientationRequested.PORTRAIT);
PrintService myPrintService = PrintServiceLookup.lookupDefaultPrintService(); //javax.print.PrintService & javax.print.PrintServiceLookup
PrinterJob job = PrinterJob.getPrinterJob(); //java.awt.print.PrinterJob
job.setPageable(new PDFPageable(aImprimir));
job.setPrintService(myPrintService);
job.print(attributes);
aImprimir.close();
}
catch(DocumentException | PrinterException | IOException | NullPointerException e){
System.out.println("Error" + e):
}
}