Convert a HTML string to PDF

Hi,

I want to convert a HTML string to PDF. I found 2 solutions :

  1. pdf.BindHTML()
  2. Dim text2 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(section, bodycontent)
    section.Paragraphs.Add(text2)

I would like to know what is the difference between two approaches.

Hi,

Thanks for using our products.

You may try using either of the following approach to convert HTML files to PDF format.

DOM approach
You can load HTML file to Document object and save the output as PDF format. Please take a look over following code snippet.

[C#]

// load HTML contents
Aspose.Pdf.Document source = new Aspose.Pdf.Document("c:/pdftest/CRWU-NDWAC-Final-Report.html", new HtmlLoadOptions());

// save output as PDF format
source.Save("c:/pdftest/ResultantFile.pdf");

BindHTML(…)
The BindHTML(…) method can be used when you need to convert HTML contents to PDF format.

InLineHTML
You may consider using this approach when you need to render HTML tags as they appear in Web browser and place HTML text along with other PDF objects. When using this approach, you can also read the source HTML file and place the contents inside PDF file.