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

Free Support Forum - aspose.com

java.lang.IllegalStateException: Font 'Times New Roman' not found

HI,
 I am using 
<artifactId>aspose-pdf</artifactId>
<version>11.1.0</version>
for converting my xml into pdf but when i am trying to convert it i am getting error i.e.
java.lang.IllegalStateException: Font 'Times New Roman' not found. Please make sure the customer font file is correctly set.


I am just using the basic example to convert the xml to pdf 
aspose.pdf.License lic = new aspose.pdf.License();

lic.setLicense(new FileInputStream(new File(“Aspose.Pdf.lic”)));

//Create pdf instance
Pdf pdf1 = new Pdf();
//Bind the source XML
pdf1.bindXML(“D:/source.xml”, null);
//Save the document

pdf1.save(“D:/HelloWorld-java.pdf”); 

I am using Mac operating system. I have gone through couple of
discussion on the internet which says that we need to install fonts on my local machine. 
I need to know did you fix this issue in any latest version of the Jar file which you have released.

Looking for a solution.

Thank you,
regards,
Chandan Sharma 

Hi Chandan,


Thanks for contacting support.

When creating PDF files from scratch or manipulating existing PDF files on Non-Windows platform, you need to have fonts installed on your system and you need to specify the path where fonts used inside PDF file are installed. You can use following methods to get system folder of fonts or set font path to font folders. Furthermore, the code snippet which you have shared earlier is based on legacy aspose.pdf package and we recommend using new Document Object Model of com.aspose.pdf package.

The following details are based on new DOM approach.

  • Document.getLocalFontPath () - shows the system folder in which project will look for fonts.
  • Document.setLocalFontPath (String) - Setting font path to custom folder

// Set font folder path
String path = “/usr/share/fonts/truetype/msttcorefonts/”;
// Adding a single font directory
//
com.aspose.pdf.Document.addLocalFontPath(path);
// setting the user list for standard font directories

java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();

list.add(path);

Given below is the code snippet to convert XML file to PDF format using new DOM approach.

[Java]
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(“surcefile.xml”, new com.aspose.pdf.XmlLoadOptions());
doc.save(“resultant.pdf”);

PS, you need to install/keep fonts in your OS default font folder path i.e. in /usr/openwin/lib/X11/fonts/TrueType/.