We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set FontName for Htmlragment

Hi,

I am trying to build pdf document from scratch instead of using XML template. I have enclosed the same program. I have set default font size and font name for the document. But when I use HtmlFragment, font size and name are not being honored. Content is displayed in times new format. How can we set font information for HtmlFragments?

Thanks

Mamatha

Hi Mamatha,


Thanks for contacting support.

When using HtmlFragment, you need to specify the font information using HTML. Please take a look over following code snippet to accomplish your requirement.

[Java]

com.aspose.pdf.Document doc = new
com.aspose.pdf.Document();<o:p></o:p>

//com.aspose.pdf.Document.addLocalFontPath(EMRPropertyManager.getAsposePdfFontsFolder());

com.aspose.pdf.Font font = com.aspose.pdf.FontRepository.findFont("Palatino Linotype");

doc.getPageInfo().getDefaultTextState().setFont(font);

doc.getPageInfo().getDefaultTextState().setFontSize(10f);

Page page = doc.getPages().add();

com.aspose.pdf.HtmlFragment fragment = new com.aspose.pdf.HtmlFragment("

It was a pleasure to see you on October 3, 2014. On behalf of all of us at EHE International, thank you for your continued participation in our Preventive Medicine and Lifestyle Management Program.

"+

"This report details my assessment of your health and recommendations based on the physical exam, current and historical laboratory results, and a summary of EHE benefits available to you throughout the year. I am sending you health information you may find useful in the proactive management of your health. I encourage you to familiarize yourself with your reported personal findings and to call me or members of your EHE health team with your questions or concerns. At the end of the report, I described a few programs that will tailor toward your needs to offer you assistance and/or guidance in the optimization of your health. Please remember that we are here throughout the year.

"+

"

The following chart summarizes your key health statistics from your exam and will serve as a baseline for future exams:

");

page.getParagraphs().add(fragment);

doc.save("c:/pdftest/peFromScratch.pdf");

Nayyer,

Thanks for the reply. I am encountering following issues.

1. When font name is "Palatino Linotype", font is not displaying in that format. When I copied the content to word it shows as PalatinoLinotype.

2. When I added size attribute to font element, content is always displaying in 27 font size. It seems pdf is not honoring size attribute.

3. Instead of adding font in the html, can we specify in a css file? Because in our case html content comes from database and it is hard to manipulate html to stylize for pdf. In legacy api, we used to add content using Text element and setting isHtmlTagSupported=true.

Thanks

Mamatha

mamatha:
1. When font name is “Palatino Linotype”, font is not displaying in that format. When I copied the content to word it shows as PalatinoLinotype.
Hi Mamatha,

Thanks for sharing the feedback.

Please share the Palatino Linotype font, so that we can test the scenario in our environment. Furthermore, when displaying contents in MS Word, proper font is used because its installed over system and proper font is referenced/loaded by MS Word when displaying contents.

mamatha:
2. When I added size attribute to font element, content is always displaying in 27 font size. It seems pdf is not honoring size attribute.
Please share the HTML string with font size information, so that we can test the scenario in our environment.

mamatha:
3. Instead of adding font in the html, can we specify in a css file? Because in our case html content comes from database and it is hard to manipulate html to stylize for pdf. In legacy api, we used to add content using Text element and setting isHtmlTagSupported=true.
When using CSS, you need to use HtmlLoadOptions object to load contents from HTML and CSS file and during rendering, the formatting is honored. Please visit the following link for further information on Convert HTML to PDF Format

Hi,

Here is sample html string for font size. I tried following approaches with HtmlFragment but it did not work.

Test paragraph


Test paragraph

This approach worked. Font size is honored when it is specified in the style attribute.

Test paragraph

Regarding HtmlLoadOptions: Sample program is converting html file into pdf. But we don't have HTML file. I am using HtmlFragments to build pdf document. In this case how can I use HtmlLoadOptions?

Thanks

Mamatha

Hi Mamatha,


Thanks for sharing additional information. We are looking into the issue and will update you asap.

We are sorry for the inconvenience caused.

Best Regards,