使用PDFBox打印PDF永远不会完成

问题描述 投票:2回答:1

我正在尝试打印一个我认为是横向模式的文件(它的尺寸为29,7 x 27厘米)但是当我提交job.print()时我的程序停止工作。这是我的代码:

PDDocument documentAllegato = PDDocument.load(new File(percorsoDaStampare +"\\"+ fileInDaStampare[k].getName()));

System.out.println("oo");
job.setPageable(new PDFPageable(documentAllegato));
System.out.println("pp");
Attribute[] attributeArray2 = attributes.toArray();
for (Attribute a : attributeArray2) {
    //System.out.println(a.getName() + ": " + a);
}
System.out.println("qq");
Attribute copies2 = attributes.get(Copies.class);
Attribute media2 = attributes.get(Media.class);
Attribute mediaPrintableArea2 = attributes.get(MediaPrintableArea.class);
Attribute mediaTray2 = attributes.get(MediaTray.class);
Attribute orientationRequested2 = attributes.get(OrientationRequested.class);
Attribute sides2 = attributes.get(Sides.class);
System.out.println("rr");
attributes.remove(Sides.class);
attributes.add(Sides.DUPLEX);
//System.out.println("PRIMA DEL PRINT");
System.out.println("ss");

job.print();

System.out.println("tt");
documentAllegato.close();   //chiudo il documento
//System.out.println("Ho finito di stampare la copia cortesia");
System.out.println("uu");
//sposto la copia di cortesia in ARCHIVIATI
File dirArchiviati = new File(pathArchiviati);
File fileCortesiaDaArch= new File(""+fileInDaStampare[k]);
System.out.println("vv");
FileUtils.copyFileToDirectory(fileCortesiaDaArch, dirArchiviati);
//System.out.println("fileDaArch "+ fileCortesiaDaArch);
System.out.println("zz");
fileCortesiaDaArch.delete();
System.out.println("FINE ALLEGATO");

我试图把它放在纵向模式修改一些东西,但我无法得到它。有什么建议?

java pdf printing pdfbox
1个回答
0
投票

我等了一个多小时才打印出来...这是一个已知的问题,在PDFBOX-3046以及herehere以及herehere中讨论过:带透明胶片或图案的文件需要很长时间才能打印出来。但你的打破记录。解决方法是将dpi值传递给PDFPageable,命令它首先渲染到图像,然后打印:

job.setPageable(new PDFPageable(documentAllegato, Orientation.AUTO, false, 300));

300是dpi值。该值越大,假脱机文件越大,使用的内存越多。

© www.soinside.com 2019 - 2024. All rights reserved.