user293914
user293914

Reputation: 111

How to print PDF file in a Java application?

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

Upvotes: 6

Views: 18047

Answers (3)

Gareth Davis
Gareth Davis

Reputation: 28069

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.

Upvotes: 5

Andrei Ciobanu
Andrei Ciobanu

Reputation: 12858

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.

Upvotes: 4

javing
javing

Reputation: 12433

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.

Upvotes: 8

Related Questions