What is the equivalent of stamper.AddJavaScript fu

2019-08-29 04:40发布

问题:

We are writing a program that needs to insert document-level JavaScript with iText 7. We founded that with iText 5, the solution was Stamper.AddJavaScript().

回答1:

It depends on the type of event you want your JavaScript code to be triggered at.

For instance, to define an action that would be executed as soon as the document is opened, use PdfDocument#getCatalog().setOpenAction.

Example for opening a print dialog when the document is opened:

pdfDocument.getCatalog().setOpenAction(PdfAction.createJavaScript("this.print(true);"));


标签: itext7