views:

319

answers:

0

Hello experts,

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.

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()