Hello,
I have crystal report and I am trying to create a pdf from the code using iText PDF API. I just have one problem.
Though Crystal reports provide option to export directly to pdf, I need to insert some JavaScript inside the pdf so that when opened it will go directly to the printer etc.
I need your help in finding a way to do something like how we do Response.BinaryWrite(blob)
I want to write the report to the pdf.
Dim blob As Byte()
Dim rpt As ReportDocument = New ReportDocument()
rpt.Load(Server.MapPath("reportNew.rpt"))
Dim strStream As New _
System.IO.BinaryReader(rpt.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat))
Dim doc As New Document()
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()
rpt.Close()
rpt = Nothing