HTML to PDF - bold and strong tags not working

Hi,


I am trying to convert HTML to PDF doc using Aspose.pdf 10.9 version.
and tags are not converted to bold text in PDF.
Sample HTML content:
Strong textBold text

Is there a way to make it work?

Thanks
Mamatha

Hi Mamatha,

Thanks for your inquiry. Please use new DOM approach for HTML to PDF conversion, it is more improved and supports bold/strong tags. Please check following documentation links for more details.

// Load HTML file into a PDF document
Document pdf = new Document(myDir + "html_strong.html", new HtmlLoadOptions());
pdf.save(myDir + "html_strong.pdf");

// Create a new document
Document doc = new Document();

// Add a new page to the document
doc.getPages().add();

// Create an HTML fragment with strong and bold text
HtmlFragment html = new HtmlFragment("Strong text Bold text");

// Add the HTML fragment to the second page's paragraphs
doc.getPages().get_Item(1).getParagraphs().add(html);

// Save the document with the HTML fragment
doc.save(myDir + "HtmlFragment_java.pdf");

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

Thanks for providing the sample code and it works. But we use it differently. We have a xml template with text segments. Programmatically we update the content in the segment. I have included sample xml template. How can add HtmlFragment to the segment or text element?

Pdf pdfDoc = new Pdf();
pdfDoc.bindXML(myDir+"sample.xml", null);
Section pdfSection = pdfDoc.getSections().get_Item("mainSection");
Segment seg = (Segment)pdfSection.getObjectByID("boldHtml");
seg.setContent("Bold TextStrong");
pdfDoc.save(myDir+"test.pdf");Pdf pdfDoc = new Pdf();
pdfDoc.bindXML(myDir+"sample.xml", null);
Section pdfSection = pdfDoc.getSections().get_Item("mainSection");
Segment seg = (Segment)pdfSection.getObjectByID("boldHtml");
seg.setContent("Bold TextStrong");
pdfDoc.save(myDir+"test.pdf");

Thanks

Mamatha

Hi Mamatha,


Thanks for sharing additional information. After initial investigation, we have logged a ticket PDFNEWJAVA-35332 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,