How to add an HTML element to PDF via iTextSharp?

2

itextsharp allows me to add your PDF elements, eg:

_documento.Add(new Paragraph("Olá"));

But I'd like to add some HTML elements, such as <h1> , or <p> , how can I do it?

_documento.Add(????);
    
asked by anonymous 22.07.2015 / 20:21

1 answer

5

You will need to use HtmlWorker :

    TextReader reader = new StringReader(html);
    HTMLWorker worker = new HTMLWorker(_documento);

    _documento.Open();
    worker.StartDocument();
    worker.Parse(reader);

    worker.EndDocument();
    worker.Close();
    _documento.Close();
    
22.07.2015 / 20:24