How do I print a PDF file from a Java application?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With