我们正在编写一个程序,需要使用 iText 7 插入文档级 JavaScript。我们发现,在 iText 5 中,解决方案是 Stamper.AddJavaScript()
。
iText 5 中看到的示例类似于
Stamper.addJavaScript(Utilities.readFileToString(".../filename.js")
其中“.../filename.js”
是包含javascript方法的文件。
在我们的例子中,我们想引用我们的 javascript 库。
最后,我们似乎可以将文档级别的 Javascript 方法直接合并到 PDF 文件中。
这是真的吗?
如果是这样,是否可以使用 iText 来做到这一点?
最佳答案
您可能正在寻找
PdfWriter writer = new PdfWriter(new File("output.pdf"));
PdfDocument pdfDocument = new PdfDocument(writer);
// dirty hack to read entire file at once
String js = new Scanner(new File("javascript_to_embed.js")).useDelimiter("\\z").next();
// set action
pdfDocument.getCatalog().setOpenAction(PdfAction.createJavaScript(js));
// add some content
// close document
pdfDocument.close();
关于javascript - 相当于 iText7 (.NET) 中的 stamper.addJavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48786168/