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.
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.
Share Improve this question edited Dec 3, 2012 at 3:02 wrschneider 18.8k17 gold badges107 silver badges189 bronze badges asked Dec 3, 2012 at 2:53 sam.tldrsam.tldr 653 silver badges9 bronze badges 2- 1 I don't think that's possible, the browser doesn't know when the PDF is open, and surely can't access the separate process for the PDF to tell to be printed. – Rubens Mariuzzo Commented Dec 3, 2012 at 2:57
- I've been told you can automatically print a pdf using javascript see: fpdf/en/script/script36.php However my question is if you can insert this javascript using iText – sam.tldr Commented Dec 3, 2012 at 3:03
1 Answer
Reset to default 7I did something like this without Javascript, using iText API calls:
PdfWriter writer = ...;
PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
writer.setOpenAction(action);