ASPOSE Word To PDF with HTML Tags

Hi,

I try to convert the a word document (which has page and section breaks) to PDF and it works fine.
Dynamically using Docx Documents we insert html tags into the word document and try to convert into PDF.
When I separately get the content as text and enable the “IsHtmlTagSupported=true” it works but page break and section break on the word document fails to render on PDF because we give only string as input.

FYI: We use Aspose 8.5 version dlls.

/
I know we can directly convert a document into PDF but there is no option to enable
HTML tags when we do that.
So tried to convert the document into html file and read the content then converted into PDF
after enabling IsHtmlTagSupported = true.
Since we do not manipulate every line we were not using Aspose snippets as mentioned below.
https://docs.aspose.com/words/net/supported-features-on-document-load/

/

Question:-
Is there a way to pass entire document as stream having HTML tags into the following line instead of a piece of string?

“Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(doc1.GetText());”

Full Code Snippet as follows:
string dataDir = @"D:\testPdf";

//Save the document as HTML file
Aspose.Words.Document doc = new Aspose.Words.Document(dataDir + “Test.docx”);
doc.Save(dataDir+“out.html”);

//Convert to PDF from HTML File - Here No option to enable HTML tags
Aspose.Words.Document doc1 = new Aspose.Words.Document(dataDir + “out.html”);
doc1.SaveOptions.ExportPrettyFormat = true;
doc1.Save(dataDir + “Html_File_to_Pdf.pdf”);

//Convert HTML File to PDF - Here we can enable HTML tags but can send only text
//not the entire file as stream
Aspose.Words.Document doc2 = new Aspose.Words.Document(dataDir + “out.html”);
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(doc2.GetText());
text2.IsHtmlTagSupported = true;
sec1.Paragraphs.Add(text2);
pdf1.Save(dataDir + “html_enabled_pdf.pdf”);

Thank you!
Regards,
Vijay

Hi Vijay,


Thanks for your inquriy. Please note Aspose.Pdf for .NET does not support DOCX document with HTML stream for conversion. You have to pass text of DOCX document with html string to Aspose.Pdf for .NET objects. Further more it is recommended to use new DOM approach for HTML to PDF conversion. Please check following documentation links for details, hopefully it will resolve the issue. However if the issue persist then please share your input/output documents here, so we will look into it and will guide you accordingly.


We are sorry for the inconvenience caused.

Best Regards,

Thank you for your reply!
I am analyzing on this.

Regards,
Vijay