HOW TO PRINT FROM JAVA A PDF FILE THAT ALREADY EXISTS?

Viewed 27

Could someone help me or give me an idea to print from java a PDF file that already exists (it is already created and must be opened from a location) then send it to the printer but not directly but modifying the margins or adjusting the document, since currently I can send it to the printer but the file has no margins which means that when printed it comes out truncated.

I am currently using 2 direct ways:

first way: Print directly

File = new File("\\Path\\filename.pdf");
Desktop.getDesktop().print(File);

the problem with this way is that for each printed file the acrobat gui opens which is annoying, it blocks the windows interface until the printing process is finished, additionally it does not allow to modify printing properties.

Second way: Use of pdfbox library

File = new File("\\Path\\filename.pdf");
PDDocument document = Loader.loadPDF(File);
job.setPageable(new PDFPageable(document));
job.print();

this form has direct communication with the printer without using acrobat, it is an agile form but I don't know how to modify file margins.

I appreciate that someone can give me an idea of ​​how adjust print size

0 Answers
Related