Free Support Forum - aspose.com

The issue convert html in pdf

hi



I have a problem customer feedback for our product pdf. If have table html in Aspose.Pdf.Generator.Text object, Generate a PDF that shows that there are more serious problems.Attached here is my test HTML file.You can try to reproduce the problem.Below is my test code.

FileStream fileStream = new FileStream(@“C:\PrintPage.html”, FileMode.Open, FileAccess.Read, FileShare.Read);

StreamReader srdPreview = new StreamReader(fileStream);

String temp = string.Empty;

while (srdPreview.Peek() > -1)

{

String input = srdPreview.ReadLine();

temp += input;



}

srdPreview.Close();

Pdf pdf = new Pdf();

Section section = pdf.Sections.Add();

Text text = new Text(temp);

text.IsHtmlTagSupported = true;

text.TextInfo.IsUnicode = true;

section.Paragraphs.Add(text);

pdf.Save(@“C:\result.pdf”);



I am using Aspose.Pdf for .NET 8.9.0.0.

Hi Zhao,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 10.6.0, where I have used new Document Object Model (DOM) to convert HTML file to PDF format and as per my observations, the resultant file is properly being converted.

Please note that Aspose.Pdf.Generator is legacy approach and we recommend using new Document Object Model.

You may consider visiting following links for further details on Convert HTML to PDF Format

I have also attached the PDF file generated over my end.

[C#]

// load source HTML file<o:p></o:p>

Document doc = new Document(@"C:\pdftest\PrintPage.html", new HtmlLoadOptions());

// save resultant PDF doucment

doc.Save(@“C:\pdftest\PrintPage.pdf”);

First of all thank you for your reply.
The way you provide is not suitable for our implementation logic.We generate PDF is containing multiple HTML text object.So I want to know whether there are alternative similar Text object method, and can solve the problem of the HTML.
Look forward to your reply

Hi Zhao,


Thanks for your feedback. Yes you can use HtmlFragment object to add HTML text in PDF document. Please check following documentation. Hopefully it will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,