I have an issue when trying to print a PDF file using Java. Here is my code:
PdfReader readFtp = new PdfReader(); // This class is used for reading a PDF file
PDDocument document = readFtp.readFTPFile(documentID);
printRequestAttributeSet.add(new PageRanges(1, 10));
job.setPageable(document);
job.print(printRequestAttributeSet); // calling for print
document.close()
I use document.silentPrint(job);
and job.print(printRequestAttributeSet);
- it works fine. If I use document.silentPrint(job);
- I can't set the PrintRequestAttributeSet
.
Can anyone tell me how to set the PrintRequestAttributeSet?
The following worked for me to print multiple PDF document with a print dialog:
Try this code:
You can also follow these steps
My Printer did not support native PDF printing.
I used the open source library Apache PDFBox https://pdfbox.apache.org to print the PDF. The printing itself is still handeled by the PrinterJob of Java.
This worked for me to print a PDF with a plain JRE:
Pageable implementation of PDDocument is deprecated, use PDPageable adapter class instead and try setPrintable instead of setPageable: