Reputation: 69
I have an html page that I need to convert it into pdf the the html page consist of gridview and images, searching on the net I came to know that this can be done using ItextSharp but when i tried it using the following code the pdf is getting generated but nothing is aligned and i am not able to get the gridview can u suggest any better methods or whats wrong with the following code?
protected void btnExportPDF_Click()
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.PDFForm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10f, 10f, 10f, 0f);
iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
Upvotes: 0
Views: 169
Reputation: 3328
1) You can try Winnovative HTML to PDF Conversion tool (paid version). Its architecture is STA.
http://www.winnovative-software.com/HTML-to-PDF-Conversion-Fine-Control.aspx
2) For a superior speed & bulk generation of PDF document with hundreds of pages, i would recommend to go for a server based software such as PDFReactor. Its license price is high. Its architecture is MTA.
I tried both of them commercially and opted PDFReactor in one of the projects where customized user Html needs to rendered into PDF file.
Upvotes: 1