问题
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