使用iTextSharp将JavaScript添加到PDF中时出现问题 [英] Problem adding javascript into PDF using iTextSharp

查看:182
本文介绍了使用iTextSharp将JavaScript添加到PDF中时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将JavaScript嵌入到使用iTextSharp创建的pdf中,如果它是代码中显示的文件,它的工作正常。

I am trying to embed JavaScript into pdf that is created using iTextSharp and it is working absolutely fine if it is a file as shown in the code.

但是当我尝试将javascript部分嵌入到它无法正常工作的内存流中。 iTextSharp是否有任何限制??

But when I try to embed the javascript part into a memory stream it is not working. Are there any limitations of iTextSharp??

Dim js As New StringBuilder
                Dim pdf As String = "c:\Print2Printer.pdf"
                Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdf, FileMode.Create))
                doc.Open()

                js.Append("var pp = this.getPrintParams();")
                js.Append("var iCopies = 2;")
                js.Append("pp.interactive = pp.constants.interactionLevel.silent;")
                js.Append("for ( var i = 0; i < 3; i++ ) { pp.firstPage = i; pp.lastPage = i;")
                js.Append("this.print(pp);")
                js.Append("}")
                Dim jaction As PdfAction = PdfAction.JavaScript(js.ToString(), writer)
                writer.AddJavaScript(jaction)

                doc.Add(New Paragraph(pdfString))
                doc.Close()


推荐答案

您的PDF尚未呈现...我不确定PDF是否有onreadystate事件,但请参阅... http://mattheyan.blogspot.com/2010/06/add-javascript-to-pdf-document-with.html

Your PDF is not rendered yet... I am not sure if PDF has a onreadystate event or not but see... http://mattheyan.blogspot.com/2010/06/add-javascript-to-pdf-document-with.html

简而言之,你需要一个setTimeout

In short you need a setTimeout

这是一个使用Docotic.Pdf http://www.codeproject.com/Articles/380293/Javascript-in-PDF

Here is an example using Docotic.Pdf http://www.codeproject.com/Articles/380293/Javascript-in-PDF

这篇关于使用iTextSharp将JavaScript添加到PDF中时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆