大家好,我在尝试用java print打印pdf文件时遇到了一个真正的问题。问题是,当我使用printed的print()方法将文件发送到打印机时,文件打印得很好,但使用真正的打印机却无法做到。`
try{
File file = new File(toprint);
InputStream is = new BufferedInputStream(new FileInputStream(file));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob job = p.createPrintJob();//p here is my printservice printer
HashPrintRequestAttributeSet printRequestSet = new HashPrintRequestAttributeSet();
HashDocAttributeSet ds=new HashDocAttributeSet();
Doc doc = new SimpleDoc(is, flavor, null);
job.print(doc, aset);
}
catch(Exception e){
System.out.println("An exception occured while printing the file "+ e);
}“我已经试过很多次了,但都不管用。”有什么想法吗?
发布于 2013-01-10 16:35:53
我认为你的打印机可能不支持pdf,在这种情况下,你将不得不使用pdf渲染器来渲染它。
查看http://java.net/projects/pdf-renderer和可分页打印页面。
如果你觉得它有帮助,我会提供代码样本。
https://stackoverflow.com/questions/5757947
复制相似问题