0

I have a html content in a variable.

I want to create a PDF document on button click with using iTextSharp dll. I searched on Google, how my PDF document can understand my HTML content, so i got HTMLWorker, it works but i don't how it's working.

  1. How this code will work to create PDF document (that can understand my HTML content).

  2. What's the use of HTMLWorker class in this code.

If any other better way to do this, then please suggest.

Can you make me understand the process of this code. It's very important for me.

        Document PdfDoc = new Document(PageSize.A4);
        PdfWriter write = PdfWriter.GetInstance(PdfDoc, Response.OutputStream);
        TextReader reader = new StringReader(paragraphBlogContent.InnerText);

        HTMLWorker worker = new HTMLWorker(PdfDoc);
        PdfDoc.Open();
        worker.StartDocument();
        worker.Parse(reader);

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;" + "filename=sample.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(PdfDoc);

        worker.EndDocument();
        worker.Close();
        PdfDoc.Close();
Puneet Chawla
  • 5,729
  • 4
  • 16
  • 33
  • 2
    `HTMLWorker` is old, obsolete and no longer supported or maintained. Instead you are encouraged to use the new `XMLWorker`. The name can be misleading but in this context it means "XHTML Worker" and as long as you pass it valid XHTML it will be fine. See [this post](http://stackoverflow.com/q/25164257/231316) for more. As to "what's the use of HTMLWorker", that's the thing that translates HTML syntax to PDF syntax. – Chris Haas Sep 13 '15 at 18:02
  • @ChrisHaas - Thanks.. I try to solve it by this link (this post). – Puneet Chawla Sep 14 '15 at 01:33

0 Answers0