sam.tldr sam.tldr - 1 year ago 194
Java Question

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.

Answer Source

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

PdfWriter writer = ...;
PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download