Convert word to PDF with html string

Hi Team,

We are using Aspose for converting docx to PDF. for some reason we need to implement HTML functionality dynamically in our document and when we convert to PDF it should apply the HTML style. But the result is not converted and it showing as a string. Could please help to resolve this issue. i have attached the sample document and converted pdf .

Hi Ramamoorthy,

Thanks for your inquiry. In case, you are creating the document from scratch and save it to PDF, we suggest you please use DocumentBuilder.InsertHtml method to insert the HTML into document.

If you want to export existing HTML in Word document into output PDF, you need to extract HTML and insert it at the same location using DocumentBuilder.InsertHtml method. Please check the following code example. Hope this helps you.

string text;
Document doc = new Document(MyDir + "Document.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph para in paragraphs)
    text = para.ToString(SaveFormat.Text);
    if (text.Contains(@"**" * *) ||
    text.Contains(@"") ||
    text.Contains(@"*" *))
        builder.MoveToParagraph(paragraphs.IndexOf(para), -1);
        builder.InsertHtml(text, true);
doc.Save(MyDir + "17.4.pdf");

It would be great if you please share complete detail of your use case. We will then provide you more information about your query along with code.

Hi Tahir.manzoor,

Thank you so much for the code, I will apply in my project and update you if i face any issues.
The sample code it’s working fine!