Open print dialog automatically when PDF opened, u

2020-03-26 03:16发布

问题:

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.

回答1:

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

PdfWriter writer = ...;
PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
writer.setOpenAction(action);