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

Java 使用PDFBox打印PDF永远不会完成,java,pdf,printing,pdfbox,Java,Pdf,Printing,Pdfbox,我正试图打印一个我认为是横向模式的文件(尺寸为29,7 x 27厘米),但当我提交作业时,我的程序停止工作。print()。这是我的密码: PDDocument documentAllegato = PDDocument.load(new File(percorsoDaStampare +"\\"+ fileInDaStampare[k].getName())); System.out.println("oo"); job.setPageable(new PDFPageable(documen

我正试图打印一个我认为是横向模式的文件(尺寸为29,7 x 27厘米),但当我提交作业时,我的程序停止工作。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");

我试着把它放在肖像模式修改一些东西,但我没能得到它。有什么建议吗?

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

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

300是dpi值。该值越大,spool文件越大,使用的内存也越多。

您的意思是29,7 x 20,7 cm?A4横向。是的,我有这个pdf,上面的页面是A4横向,我的代码在“job.print()”行停止工作。我用A4格式打印文件时没有错误。我自己也不知道。使用java-Xmx1g之类的工具增加内存。或者调用
documentalegato.close()作业前
打印()我在其他文件上使用了相同的功能,它可以工作。唯一的区别是有问题的是在横向模式下的pdf。你似乎已经接近了错误。如果没有人有这个错误并给出了答案,请尽量少用。风景没什么特别的,也许更多的是记忆。我不知道你是谁,但你让我开心!非常感谢,现在我可以打印了,我学到了一些有用的东西!