使用 javax.print 打印 pdf 文件
大家好, 我在尝试使用 java print 打印 pdf 文件时遇到了一个真正的问题。 问题是,当我使用带有可爱 pdf 的 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);
}
` 我已经尝试了很多次但没有成功。 有什么想法吗?
Hey everyone ,
I'm facing a real problem here while trying to print a pdf file using java print .
The problem is that when i send the file to the printer using print() method with cute pdf the file is well printed but with a real printer it couldn't be done .
`
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);
}
`
I've tried it so many times but it doesn't work.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的打印机可能不支持 pdf,在这种情况下,您将必须使用 pdf 渲染器来渲染它。
查看 http://java.net/projects/pdf-renderer 和可分页打印页面。
如果您觉得有帮助,我将提供代码示例。
I think your printer may not have support for pdf, in this case you will have to render it using a pdf renderer.
Look at http://java.net/projects/pdf-renderer and pageable print page.
If you find it helpful I will provide code samples.