How to print PDF file in a Java application?

本小妞迷上赌 提交于 2019-12-22 04:42:47

问题


How do I print a PDF file from a Java application?


回答1:


Here some source code that will allow you print any text file:

public void print() {
    //The desktop api can help calling other applications in our machine
    //and also many other features...
    Desktop desktop = Desktop.getDesktop();
    try {
    //desktop.print(new File("DocXfile.docx"));
        desktop.print(new File("Docfile.pdf"));
    } catch (IOException e) {           
        e.printStackTrace();
    }
}

Maybe it suit your needs since you did not give more details.




回答2:


Try PDF Renderer. It's open source and there are a couple of examples on the site on how to render to a printer device.




回答3:


I've used PDFBox before for a similar task like yours. It's an excellent library from the Apache Software Foundation. The class you are probably going to use is called: PDFTextStripper . The javadoc for the class can be found here.



来源:https://stackoverflow.com/questions/2478890/how-to-print-pdf-file-in-a-java-application

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