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

Free Support Forum - aspose.com

Converting Documents to PDF - Error when code executes in Solaris environment

Hello again,

I’m using using aspose.words to convert an input stream to a PDF, by creating a java.io.File from an InputStream, an aspose.words.Document from the File, and using the saveToPdf() method.

Everything worked perfectly during development, in a Windows Xp environment. However, when my code was put into our test servers, which run on Solaris, I get a NullPointerException with some operation on the Document.

I’m attaching the stack trace, and the relevant code of my conversion method. Let me know if there’s anything else I can provide.

Thanks!

Hi Mark,

Thanks for your inquiry. It appears that your application is having a problem finding the font files on your test enviroment, where as it does not have this problem on the XP enviroment.

Please try using this code below to manually set the TrueType font directory. Also make sure that your program has access rights to the fonts folder.

Document doc = new Document("in.doc");<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

PdfOptions opt = new PdfOptions();

opt.setTrueTypeFontsFolder("/usr/share/fonts");

doc.saveToPdf(0, doc.getPageCount(), "out.pdf", opt);

Thanks,

Hi Adam,

Thanks for the quick response. We haven’t been able to test this fix yet (server admin’s out and the fonts still need to be actually installed on our server machine… we suspect) but I wanted to clarify that, according to the stack trace, it’s the doc.getPageCount() method call that is causing the exception, and not the saveToPdf method.

Since your code is just modifying the saveToPdf call, is it possible that something else could be wrong?

Just wondering… I’ll know more tomorrow when the fonts are installed on our solaris machine.

Hi Mark,

Thanks for your inquiry.

Yes this exception is occuring in the GetPageCount method but is more accurately occuring further down the line in a method being called by GetPageCount. For example updatePageLayout is being called which calls a bunch of other methods to achieve it's calculations, one of which is found in TTFontFiler.java which is causing an exception. This most likely means it is a problem to do with fonts and specifying the font directory should fix this.

Thanks,

Just following up: the solution provided worked. We didn’t even have to install new fonts. Our solaris machine had a set of default truetype fonts, and as soon as set the file path to the directory containing these fonts everything worked fine.

Hi Mark,

Thank you for sharing this information with us. It's great that it is working well now.

If you have any further queries please feel free to ask.

Thanks,