Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open print dialog automatically when PDF opened, using iText

I need to be able provide the print dialog automatically when a pdf is opened. I need to do it with javascript and I was wondering if it is possible for me to append said javascript using iText? It would be much cleaner for me to do so because I am currently already utilizing the iText library. Otherwise is there a better way to do this? Currently using:

Document document = new Document();
document.add(New Paragraph("<script type="text/javascript">print();</script>"));

This, however, makes no changes to the pdf but still does not print when it is opened.

Thanks in advance.

like image 328
sam.tldr Avatar asked Nov 29 '25 22:11

sam.tldr


1 Answers

I did something like this without Javascript, using iText API calls:

PdfWriter writer = ...;
PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
writer.setOpenAction(action);
like image 153
wrschneider Avatar answered Dec 01 '25 12:12

wrschneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!