Given you are already using itextsharp, you should start from here:
Chapter 1: Hello HTML to PDF[
^]
With itext, it would be as simple as:
public void createPdf(string html, string dest)
{
HtmlConverter.ConvertToPdf(html, new FileStream(dest, FileMode.Create));
}
In case you are using
pdfHTML
. (An iText 7 add-on for Java and C#), a simple example for converting HTML to PDF using iText in C# would be:
static void Main(string[] args)
{
using (FileStream htmlSource = File.Open("input.html", FileMode.Open))
using (FileStream pdfDest = File.Open("output.pdf", FileMode.Create))
{
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties);
}
}
For complete details, refer:
Convert HTML & CSS to rich, smart PDF documents - iText[
^]