Save Image Html to PDF

Hello Aspose Team,

Do any one know how to add image htmls to the pdf document using aspose.pdf

Im my .aspx page I have 3 div's. I need to display each div content in a separate page of pdf. im succesful with this.But im searching code to convert each div content to an image html and then save it to pdf.

Please find the sample code below.

Dim SB1 As New StringBuilder
Dim SW1 As New StringWriter(SB1)
Dim htmlTW1 As New HtmlTextWriter(SW1)
ShowValuesDiv.RenderControl(htmlTW1)
Dim dataGridHTML1 As String = SB1.ToString()
Dim sec2 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()
Dim text2 As New Aspose.Pdf.Generator.Text(sec2, dataGridHTML1)
text2.IsHtmlTagSupported = True
sec2.Paragraphs.Add(text2)

Dim SB2 As New StringBuilder
Dim SW2 As New StringWriter(SB2)
Dim htmlTW2 As New HtmlTextWriter(SW2)
ShowValuesDiv2.RenderControl(htmlTW2)
Dim dataGridHTML2 As String = SB2.ToString()
Dim sec3 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()
Dim text3 As New Aspose.Pdf.Generator.Text(sec3, dataGridHTML2)
text3.IsHtmlTagSupported = True
sec3.Paragraphs.Add(text3)

sSavePath = ""
pdf1.Save(sSavePath)

Hi Leelak,


Thanks for contacting support.

Aspose.Pdf for .NET offers the feature to convert HTML pages to PDF format and as I can notice, you are using legacy Aspose.Pdf.Generator namespace. So we recommend using new Document Object Model (DOM) of Aspose.Pdf namespace. In case you encounter any issue, please feel free to contact. For further details, please visit Convert HTML to PDF Format

In case you encounter any issue, please share the resource files so that we can test the scenario in our environment.

Im seeing this error
Type HtmlLoadoptions is not defined

Does DOM approach works for .NET 2.0 framework
appreciate your quick response

Hi Leelak,

HTML to PDF conversion is supported over .NET Framework 2.0. During my testing with Aspose.Pdf for .NET 10.3.0, where I have set the target framework of my application to .NET Framework 2.0 and have used Aspose.Pdf.dll from the net2.0 folder of the Aspose.Pdf for .NET installation directory, I am unable to notice any issue and one of my sample HTML files is properly being converted to PDF format.

C#

Aspose.Pdf.HtmlLoadOptions load = new Aspose.Pdf.HtmlLoadOptions();
Aspose.Pdf.Document doc = new Aspose.Pdf.Document("c:/pdftest/pieChart.html", load);
doc.Save("c:/pdftest/HTMLtoPDFconversion.pdf");

Hi Nayyer, when I try to add aspose.pdf as reference 8.8 or above. I see a warning message that the framework needs to be updated to 4.0 or above

that is the reason ,I had to in the old way using 6.6 ,because i don’t see aspose.HtmlLoadoptions in the reference

When I type aspose.pdf.HtmlLoadOptions I see an error Type Aspose.pdf.HtmlLoadoptions is not defined

Hi Leelak,


The HtmlLoadoptions was introduced in one of the recent release versions and its not available in older release of Aspose.Pdf for .NET 6.6.0. Furthermore, we always recommend our customers to try migrating to latest release as all the enhancements and bus fixes are introduced in latest release versions.