0

Can anybody help me how to export Repeater data to PDF file without using iTextSharp. I am generating PDF files from Repeater control using iTextSharp, it works properly but are there any other suggestions on how to export repeater data to a PDF document?

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44

1 Answers1

1

use the below code.Hope it will resolve your issue.

using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Text;

protected void BtnExportToPdf_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        Repeater1.DataBind(); 
        Repeater1.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f,10f,10f,0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();  
    }
Jack
  • 253
  • 3
  • 8