BACK
TOP
Convert HTML to PDF with iTextSharp directly
Matías Creimerman - Buenos Aires, Argentina - 2013-04-15

The best way to create PDFs with iTextSharp is programmatically because we have more options for drawing it.
But there is an option with some limitations that is to assemble an HTML according to the specifications to have a correct PDF file.

public void HTMLToPDF(string html, string fullDestinyFilePath)
        {
            StringWriter sw = new StringWriter();
            sw.WriteLine(html);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document();
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, new FileStream(fullDestinyFilePath, FileMode.Create));
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
        }
This content is property of Matias Creimerman
Any misuse of this material will be punishable
This work is licensed under a
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License
Creative Commons License