![](/img/trans.png)
[英]Printing plain text files to PDF printer using javax.print results in an empty file
[英]Printing a pdf file using javax.print
大家好,我在嘗試使用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);
}
`我已經嘗試了很多次,但是沒有用。 有任何想法嗎?
我認為您的打印機可能不支持pdf,在這種情況下,您將不得不使用pdf渲染器進行渲染。
查看http://java.net/projects/pdf-renderer和可分頁的打印頁面。
如果您覺得有幫助,我將提供代碼示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.