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

Free Support Forum - aspose.com

Converting HTML with font-family

The CSS font-family seems not to be respected when converting an HTML file to PDF. Can you help me getting this to work?

The font I’ve declared in CSS is embedded on the application where Aspose runs in. But not on operating system level. With other file formats (DOC, PPT, …) the same font can be used successfully. You’ll find the PDF output I received as an attachment. I’m Running Aspose.Pdf for Java 10.8.1. And this is what I used as an input:

body {
font-family: FrutigerNext;
font-size: 30pt;
Hello World

Hi Jonas,

Thanks for your inquiry. Your query is related to Aspose.Pdf. I am moving this forum thread to Aspose.Pdf forum. Aspose.Pdf team will reply you shortly about your query.

I’m not quite sure if it’s a PDF issue. But maybe that’s the part I’m doing wrong…

The reading part is being done by Aspose Words:
com.aspose.words.Document doc = new com.aspose.words.Document(html);

Besides, converting a PPT, DOC, etc. works perfectly fine.

Hi Jonas,

Thanks for contacting support.

When generating PDF files using Aspose.Pdf for Java where you are using custom font during PDF file generation, that specific font needs to be installed on system where PDF creation code is being executed. Please install the font over system and then try performing the conversion and in case you encounter any issue, please share the font file, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Thanks for your response!

That’s correct. I’m using a custom font. Sorry to tell you that I cannot provide you the font I’m using due to licence restriction. But you can choose any custom font you might have yourself to try and reproduce the problem. As long as you use the same font name in the CSS-part of HTML.

As I’ve mentioned earlier, writing PDFs with the specific custom font is not the problem I’m facing. This works fine with DOC, PPT, etc. It just does not work with HTML. So please understand that the focus of our research should be adjusted to interpreting HTML. Not generating PDF. Therefore you have all files and source code you need to try and reproduce the behaviour I’m having trouble with.

Hi Jonas,

Thanks for sharing the details.

In order to test the scenario, I have used Andy Bold font and when viewing the HTML file in web browser and when converting this HTML file to PDF format using Aspose.Pdf for Java 11.3.0 in Eclipse Juno project with JDK 1.7 running over Widows 7 x64 and as per my observations, the HTML contents are properly being rendered using Andy Bold font. For your reference, I have also attached the output generated over my end.


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

com.aspose.pdf.Document doc = new com.aspose.pdf.Document("C:\\htmltest.html", new com.aspose.pdf.HtmlLoadOptions());

// save output as PDF format