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?
Asked
Active
Viewed 3,192 times
0
-
1If you don't want to use iTextSharp I think you will have to write your own library. – unlimit Jul 09 '13 at 11:19
-
there is no other library? – Pradeep Basnet Jul 09 '13 at 11:24
-
2what's wrong with iTextSharp? – Alexis Pigeon Jul 09 '13 at 12:20
-
1Of course there are other libraries, too, e.g. PDFBox, PDF Clown, etc. But what improvements are you actually looking for? Depending on that, others might tell whether any of those is a better choice for you. – mkl Jul 09 '13 at 12:57
1 Answers
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