使用javax.print打印pdf文件

时间:2021-12-02 15:15:04

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 . `

嘿大家,我在尝试使用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);
}

` I've tried it so many times but it doesn't work. Any ideas?

“我已经尝试了很多次,但它不起作用。有任何想法吗?

1 个解决方案

#1


0  

I think your printer may not have support for pdf, in this case you will have to render it using a pdf renderer.

我认为你的打印机可能不支持pdf,在这种情况下你必须使用pdf渲染器渲染它。

Look at http://java.net/projects/pdf-renderer and pageable print page.

查看http://java.net/projects/pdf-renderer和可分页打印页面。

If you find it helpful I will provide code samples.

如果您发现它有用,我将提供代码示例。

#1


0  

I think your printer may not have support for pdf, in this case you will have to render it using a pdf renderer.

我认为你的打印机可能不支持pdf,在这种情况下你必须使用pdf渲染器渲染它。

Look at http://java.net/projects/pdf-renderer and pageable print page.

查看http://java.net/projects/pdf-renderer和可分页打印页面。

If you find it helpful I will provide code samples.

如果您发现它有用,我将提供代码示例。