Printing a PDF duplex using Java

时光怂恿深爱的人放手 提交于 2019-12-13 06:26:48

问题


i have a printer attached to CUPS, it supports duplex printing, how can i set it to print simplex or duplex through my java routine?

i have attempted using itext libraries using the ASET add and the addViewerPreference without any luck.

can anyone offer some suggestions?


回答1:


I've created a small ChangeViewerPreference code sample that adds a viewer preference to an existing PDF:

PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.addViewerPreference(PdfName.DUPLEX, PdfName.DUPLEXFLIPLONGEDGE);
stamper.close();
reader.close();

Possible values for this viewer preference are PdfName.SIMPLEX, PdfName.DUPLEXFLIPSHORTEDGE and PdfName.DUPLEXFLIPLONGEDGE. This code implements ISO-32000-1 and works with all viewers that have implemented the viewer preferences as defined in ISO-32000-1. This isn't the case for all viewers you'll find on the market. Maybe that's why you don't have any luck.

Which tool are you using to render the PDF? (Note that I have no idea what "ASET add" means, so you may want to clarify.)




回答2:


When using IPP you should set the job-attribute sides = two-sided-long-edge

https://docs.oracle.com/javase/7/docs/api/javax/print/attribute/standard/Sides.html



来源:https://stackoverflow.com/questions/21827760/printing-a-pdf-duplex-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!