This is a migrated thread and some comments may be shown as answers.

Migrating from iTextSharp to Telerik Report

0 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
RJ
Top achievements
Rank 1
RJ asked on 24 May 2012, 09:33 AM
Hi I'm just wondering if I can migrate my iTextSharp Report to Telerik Report. Its purely code behind and all it needs are just imports and it will make my datasource be downloaded or viewed as pdf.

Heres my sample code in iTextSharp:

Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html
Imports iTextSharp.text.html.simpleparser


 Private Sub ExportToPDF(ByVal dtS As DataTable)
        dtR As New DataTable, dr As DataRow, dg As New DataGrid

        dg.GridLines = GridLines.Both
        dg.ForeColor = Color.Black
        dg.AutoGenerateColumns = False

        dtR.Columns.Add("INVOICE_NO", Type.GetType("System.String"))
        dtR.Columns.Add("INVOICE_DATE", Type.GetType("System.String"))
        dtR.Columns.Add("CLIENT", Type.GetType("System.String"))
        dtR.Columns.Add("INVOICE_AMT", Type.GetType("System.Decimal"))
        dtR.Columns.Add("TOTAL_DUE", Type.GetType("System.Decimal"))
        dtR.Columns.Add("PAID_AMT", Type.GetType("System.Decimal"))
        dtR.Columns.Add("PAID_DATE", Type.GetType("System.String"))

        CreatePDFColumn(dg, "INVOICE_NO", "Invoice<br>No.", "{0:########0;(########0); }")
        CreatePDFColumn(dg, "INVOICE_DATE", "Invoice<br>Date", "")
        CreatePDFColumn(dg, "CLIENT", "Client Name", "")
        CreatePDFColumn(dg, "INVOICE_AMT", "Invoice<br>Amount", "{0:###,###,##0;(###,###,##0); }")
        CreatePDFColumn(dg, "TOTAL_DUE", "Total<br>Due", "{0:###,###,##0;(###,###,##0); }")
        CreatePDFColumn(dg, "PAID_AMT", "Paid<br>Amount", "{0:###,###,##0;(###,###,##0); }")
        CreatePDFColumn(dg, "PAID_DATE", "Paid<br>Date", "")

 

        Dim drR As DataRow
        For Each dr In dtS.Rows
            drR = dtR.NewRow
            drR("INVOICE_NO") = dr("INVOICE_NO")
            drR("INVOICE_DATE") = dr("INVOICE_DATE")
            drR("CLIENT") = dr("CLIENT")
            drR("INVOICE_AMT") = dr("INVOICE_AMT")
            drR("TOTAL_DUE") = dr("TOTAL_DUE")
            drR("PAID_AMT") = dr("PAID_AMT")
            drR("PAID_DATE") = dr("PAID_DATE")
            dtR.Rows.Add(drR)
        Next
        drR = dtR.NewRow
        drR("INVOICE_NO") = ""
        drR("INVOICE_DATE") = ""
        drR("CLIENT") = "Total:""
        drR("INVOICE_AMT") = Me.lblInvoiceAmt.Text
        drR("TOTAL_DUE") = Me.lblTotalDue.Text
        drR("PAID_AMT") = Me.lblPaidAmt.Text
        drR("PAID_DATE") = ""
        dtR.Rows.Add(drR)

        Response.Clear()
        Dim dv As New DataView(dtR)
  
        Dim sw As System.IO.StringWriter = New System.IO.StringWriter
        Dim hw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(sw)
        hw.WriteLine("<b><u><font size='2'>" & _
             "Invoice List:" & _
             "</font></u></b>")
        hw.WriteLine("<br><br>&nbsp;")
        dg.DataSource = dv
        dg.HeaderStyle.Font.Bold = True
        dg.DataBind()
        dg.RenderControl(hw)

        Response.ContentType = "application/pdf"
        Response.AddHeader("content-disposition", "attachment;filename=InvoiceReport.pdf")

        Dim sr As New StringReader(sw.ToString())
        Dim pdfDoc As New Document(PageSize.A4.Rotate, 10.0F, 10.0F, 10.0F, 0.0F)
        Dim htmlparser As New HTMLWorker(pdfDoc)

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
        pdfDoc.Open()
        htmlparser.Parse(sr)
        pdfDoc.Close()
        Response.Write(pdfDoc)
        Response.End()
    End Sub

 

 

 

 

 

 

 

 

 


No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
RJ
Top achievements
Rank 1
Share this question
or