Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print PDF file in a Java application?

Tags:

java

printing

pdf

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

like image 848
user293914 Avatar asked Mar 19 '10 16:03

user293914


People also ask

How do I print a PDF in JavaScript?

Print PDF File Using the iframe Tag in JavaScript In our HTML document, we have to create a button inside the body tag, and then we have to link our JavaScript file using the script tag. We will add an onclick event, and then we will pass a function printPdf() as a value to this event.

Can Java read PDF files?

To read an existing PDF document, you need to create a PdfDocument object and then call its "load" method with the file pathname or a memory stream containing the PDF file. Once you create the PdfDocument object, you can use the object's methods to read from the loaded document.


1 Answers

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.

like image 103
javing Avatar answered Sep 27 '22 22:09

javing