HTML to PDF convertion not working

Hi,


I have a html file “Source.htm” and when I am trying to convert it to pdf format it throwing an exception(both souce file and error image are attached as “File.rar”).
Below is my code, please have a look on it and give some suggestion for
this issue.

Code
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“E:\Aspose.Pdf.lic”);

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

StreamReader sr = File.OpenText(@“E:\SVN\AffordableCare\HTMLSource\Source.htm”);
Aspose.Pdf.Generator.Text tempText = new Aspose.Pdf.Generator.Text(section, sr.ReadToEnd());
tempText .IsHtmlTagSupported = true;
section.Paragraphs.Add(tempText );

pdf.Save(@“E:\SVN\AffordableCare\HTMLSource\Result.pdf”);

Thank you
Kali Charan Dash


Hi Kali,


Thanks for your inquiry. Please use new DOM approach to convert HTML to PDF, please find enclosed output document. Kindly check following code snippet for the purpose.


HtmlLoadOptions options = new HtmlLoadOptions();<o:p></o:p>

// use the new conversion engine

options.UseNewConversionEngine = true;

// load HTML file

Document pdfDocument = new Document(myDir + "Source.htm", options);

pdfDocument.Save(myDir + "HTMLtoPDF_DOM.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal

Thanks for your email. Below is the code that I tried as you suggested but getting exceptions.

Code

HtmlLoadOptions options = new HtmlLoadOptions();
// use the new conversion engine
options.UseNewConversionEngine = true;
// load HTML file
Document pdfDocument = new Document(@“E:\SVN\AffordableCare\HTMLSource\Source.htm”, options);
pdfDocument.Save(@“E:\SVN\AffordableCare\HTMLSource\HTMLtoPDF_DOM.pdf”);

.Below are different scenarios .

Scenario 1 : (used Aspose.Pdf.dll 7.0 version with valid License)
Exception : Got an exception "
‘Aspose.Pdf.HtmlLoadOptions’ does not contain a definition for ‘UseNewConversionEngine’ and no extension method ‘UseNewConversionEngine’ accepting a first argument of type ‘Aspose.Pdf.HtmlLoadOptions’ could be found (are you missing a using directive or an assembly reference?)"
for code "
options.UseNewConversionEngine = true;"


Scenario 2 : (used Aspose.Pdf.dll 9.0 version with valid License)
Exception : Got an exception
"System.InvalidOperationException:
The subscription included in this license allows free upgrades until 20
Jun 2013,
but this version of the product was released on 27 Feb 2014.
Please renew the subscription or use a previous version of the product."


Scenario 3 : (used Aspose.Pdf.dll 9.0 version without License)
Exception : Got an exception “
System.ArgumentException: At most 4 text fragments can be added in evaluation mode.” for code " Document pdfDocument = new Document(@“E:\SVN\AffordableCare\HTMLSource\Source.htm”, options);"

please help me out to fix this issue.

Thank you.

Hi Kali,


Thanks for your feedback. It seems your subscription is expired and you need to renew it. You may request for 30 days temporary license to test the issue resolution and later you can proceed for subscription renewal accordingly.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

I have tried with the temporary license and able to generate the pdf file. But the generated .pdf file design is disturbed(alignment and design) as compare to the source html file(reference attached). Please check and let me know how to fix it.

thanks.

Hi Kali,


Thanks for sharing the details.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-36509 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.

The issues you have found earlier (filed as PDFNET-36509) have been fixed in Aspose.PDF for .NET 20.1.