How to add an HTML element to the PDF via iTextSharp?

Asked

Viewed 393 times

2

itextsharp allows me to add your PDF elements, example:

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

But I would like to add some elements of HTML such as a <h1>, or a <p>, how can I do?

_documento.Add(????);

1 answer

5


You will need to use a HtmlWorker:

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

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

    worker.EndDocument();
    worker.Close();
    _documento.Close();
  • 1

    I was doing it right then. Only now did I realize that the error was because my html had an image in which src was filled with a Base64 image and not linking to a file. That’s the real problem, I’ll look for a solution and if I don’t find another question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.