Darshan Kodkany
Darshan Kodkany

Reputation: 69

HTML to pdf conversion not happening

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

Answers (2)

Karan
Karan

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.

http://www.pdfreactor.com/

Upvotes: 1

Evale
Evale

Reputation: 29

You can try using GemBox.Document, I think it might suit your needs.

Upvotes: 0

Related Questions