We help IT Professionals succeed at work.
Get Started

ITextSharp Binary Data issue

1,404 Views
Last Modified: 2012-05-07
Hello,

I have a crystal report in my ASP.net application and I am programmatically trying to create a pdf from that using ItextSharp. I do understand that from Crystal report you can export the report to pdf.

The reason I am again doing it from iTextSharp is that I need to embedd some javaScript into the pdf as shown in my code.

The problem I am facing is, I don't know how to add the binary data from the report into the                 doc.Add(New Paragraph(blob ))

If I just write a string value inot                 doc.Add(New Paragraph("Please print pdf" )) it is working absolutely fine.

Thanks in advance
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(blob ))
                doc.Close()
 
                rpt.Close()
                rpt = Nothing

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE