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);"));