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

Free Support Forum - aspose.com

HTML to PDF Conversion on Linux

I am attempting to do an HTML to PDF conversion on a linux system using the following code snippet:

HtmlLoadOptions html = new HtmlLoadOptions();
html.setUseNewConversionEngine(true);
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(m_fileData.getSourceFileFullPath(), html);
doc.save(outStream);
Having previously used this code to set the Font Folders:
com.aspose.pdf.Document.addLocalFontPath(fontFolder);
However, the conversion is not respecting the fonts whereas it does in the windows environment. Is there something else that I need to do to set up the fonts for conversion on linux?

Hi Michael,


Thanks for your inquiry. Please note font used in HTML must be present on your machine and you need to set font folder path on non-windows machine as you mentioned above.

Moreover please also check following code snippet to set font path if there are more than one font path. Hopefully it will help you to accomplish the task.


//geting the list for standard font directories in different OS<o:p></o:p>

java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();<o:p></o:p>

//seting the user list for standard font directories<o:p></o:p>

list.add(“c:\fonts2\”);<o:p></o:p>

list.add(“c:\fonts3\”);<o:p></o:p>

com.aspose.pdf.Document.setLocalFontPaths(list);<o:p></o:p>

//Restoring list for standard font directories by default.<o:p></o:p>

com.aspose.pdf.Document.restoreLocalFontPath();<o:p></o:p>

<o:p> </o:p>

<o:p>Please feel free to contact us for any further assistance.</o:p>

<o:p>
</o:p>

<o:p>Best Regards,</o:p>

<o:p>
</o:p>

What is the difference between using getLocalFontPaths followed by setLocalFontPaths as opposed to using addLocalFontPaths?


My problem is that I used addLocalFontPaths, pointed at the folders where the fonts were located, but the fonts were not used in the conversion to pdf.

HI Michael,


Thanks for your inquiry. Please note addLocalFontPath(String) is used to add a single font path to fonts directories and whereas setLocalFontPaths(List) is used to add more than one fonts into font directories. Hopefully this detail will help you set font paths appropriately. If issue persist then please share your sample document and code here, so we will look into it and will guide you accordingly.

Document.addLocalFontPath (String) - Add one more path to fonts.


Document.getLocalFontPaths () - Get List for standard font directories in which our project will look for fonts
Document.setLocalFontPaths (List) - Sets user list with font paths.


Please feel free to contact us for any further assistance.

Best Regards,

Okay, but if I were to run addLocalFontPath in a loop iterating through all of my font location it would essentially be the same as add them to a list in a loop and then using setLocalFontPaths.


Currently my code looks like this:
for(String fontFolder : m_fileData.getFontFolders()) {
LOG.debug(“Adding folder with path: " + fontFolder + " to pdf font folder sources.”);
com.aspose.pdf.Document.addLocalFontPath(fontFolder);
}



HtmlLoadOptions html = new HtmlLoadOptions();
html.setUseNewConversionEngine(true);
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(m_fileData.getSourceFileFullPath(), html);
doc.save(outStream);

Hi Michael,


Thanks for sharing your source code. Please also share your input and output files, so we will look into it and will provide you more information accordingly.

Best Regards,

The attached result is when running in linux. When run in windows the fonts as well as bolding, italicizing, and underlining also work.

Hi Michael,


Thanks for sharing source file. We have tested
the scenario over Ubuntu 13.10 using Microsoft fonts unable to replicate the issue. It seems it is font
related issue at your machine. Can you please test the scenario with
Microsoft fonts and share the results? So we will investigate it
further.

sudo apt-get install ttf-mscorefonts-installer

// Set font folder path
String path = “/usr/share/fonts/truetype/msttcorefonts/”;
// Adding a single font directory
// com.aspose.pdf.Document.addLocalFontPath(path);

// seting the user list for standard font directories
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
list.add(path);

com.aspose.pdf.Document.setLocalFontPaths(list);
HtmlLoadOptions html = new HtmlLoadOptions();
html.setUseNewConversionEngine(true);
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(“HTML To PDF.html”, html);
doc.save(“HTMLtoPDFDOM.pdf”);

We are sorry for the inconvenience caused.

Best Regards,