Free Support Forum -

Converting pdf to images - "Can not load:com/aspose/pdf/kit/res/defaultfont/Times-Roman.afm"


I’m using the 4.0 java pdf kit jar and trying to convert a pdf document to images. When the doConvert() method is called, I get the following message in my server log:

"Can not load:com/aspose/pdf/kit/res/defaultfont/Times-Roman.afm"

I tried importing com.aspose.pdf.kit.PdfConverter but the message persists.

Here’s my code (note that pdfDoc was declared elsewhere, and is a Document constructed from a pdf InputStream)):
PdfConverter converter = new PdfConverter();
String suffix = “.jpg”;
int imageCount = 0;
converter.bindPdf(saveDir + File.separator + fileName + “.pdf”);
converter.setEndPage(pdfDoc.getNumberOfPages() - 1);

while(converter.hasNextImage()) {
converter.getNextImage(saveDir + File.separator + “page” + imageCount + suffix,ImageType.JPEG);
logger.debug("saving image " + imageCount);

Any help would be appreciated here. I have the conversion working with a different implementation, but I’d like to use Aspose since we have a complete license and are using the libraries elsewhere for conversion and such.


Hi Mark,

Can you please make sure that you’re using the latest version of the Aspose.Pdf.Kit for Java at your end? Also, you need to set the start and end pages from 1 to N ( where N = total pages); moreover, if you want to process all the pages, you don’t need to set the start and end pages.

Please try the latest version at your end and see if it helps. If you still find the issue at your end then please share a sample PDF file with us, so we could test the issue at our end.

We’re sorry for the inconvenience.

Ok, I re-downloaded my pdf.kit jar and my JAI jars for good measure to ensure the latest versions.

My pdf to image conversion code from the original post comes after processing of the file’s InputStream by a toPdf conversion service, and I’m noticing different behavior when I get to image conersion from the pdf.kit’s doConvert() method, based on what type of original file was converted to Pdf.

When I start with a text file InputStream, I use:
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.getSections().add();

DataInputStream in = new DataInputStream(is);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;

while((strLine = br.readLine()) != null) {
Text text1 = new Text(sec1,strLine);

byte[] bais = pdf1.getBuffer();
return new ByteArrayInputStream(bais);

to convert to PDF. Image conversion causes the “Can not
load:com/aspose/pdf/kit/res/defaultfont/Times-Roman.afm” message spam and empty image files are created. I did browse through the aspose.pdf.kit.jar and verify that it contains com/aspose/pdf/kit/res/defaultfont/TimesRoman.afm

Starting with a pdf file, I write the IS to a byte array, create an Aspose.pdf.kit.PdfFileInfo object from the array and check the beEncrypted() method, then reconstruct the IS from the array and move on to conversion. In this case, I get an “ExceptionInitializationError” and stack trace when I hit image conversion and the doConvert() method is called.

Finally, when using any other document type, if it’s Aspose-supported I create a Document from the IS and use the aspose.words.Document saveToPdf method. In this scenario the resulting pdf InputStream is actually converted to images and displayed back! The quality isn’t amazing though… the font looks a little off.

The resulting Pdfs are all valid and seem fine, and can be converted to images with another implementation.

Attached are my three unconverted files, and the converted pdfs from each which are struggling at the image conversion step. Let me know if there’s anything else I can provide.


Hi Mark,

Thank you very much for sharing the sample files and the details. We’ll test the issue at our end and you’ll be updated accordingly.

We’re sorry for the inconvenience.

Hi Mark,

I have tested the attached PDF files at my end and these files were successfully converted to the images. Can you please share any further details that can help us reproduce the issue at our end? For example, your development environment where you’re having this issue, or any other related information. In fact, it is very important for our development team to reproduce and understand the issue before it can be resolved.

We’re sorry for the inconvenience and appreciate your cooperation.


Sorry it took so long to reply. I’m working in JDeveloper I just downloaded the 3.1.0 pdf.kit release and retried the conversion to images. It still doesn’t work, same issues as before.

The complete process of conversion is:
I’m using an af:inputFile component to select the file to upload.
A backing bean method creates an UploadedFile object from the component’s value.
The UploadedFile’s .getInputStream() is passed to a managing method which selects
different conversion pathways based on file type.
The resulting InputStream is passed to a conversion method, which uses the code from my original post.
The image pages are saved to a temp folder, and basically a list of the image attributes is passed back and referenced by a servlet to display the pictures in a carousel.

There is a lot of code represented in that process, but if there are any particular sections that might be helpful let me know and I can post a code sample.

Ultimately, of course, the error is consistently popping up in the converter.doConvert() call.

You mentioned that you were able to convert the pdf files I uploaded to images successfully… did you do anything differently from the code in my original post? Again, if you were able to convert the pdf files I uploaded to images, then my conversion to pdf service must be fine… and it’s just an issue with my pdf.kit converter method… which is confusing, because I have the most recent version, and I’m just importing the com.aspose.pdf.kit.ImageType and PdfConverter classes…

By the way, do you know what situation causes the “Can not load” message that appears in the title of this thread?

Anyway, just let me know if there is any more information that would be helpful and I’ll be happy to share it! Thank you for your support.

Hi Mark,

We need to investigate this issue in detail at our end. Please spare us some time and you’ll be updated with the results accordingly.

We’re sorry for the inconvenience.

Hi Mark,

Can you please share whether you’re using Aspose.Pdf.Kit for Java in Windows or Linux/Unix environment?


I’m use Windows XP for local development (where the error is occurring).

Eventually, my code will be deployed on a Solaris-based environment though.

Hi Mark,

Thank you very much for sharing the details. We’ll further investigate this issue and you’ll be updated accordingly.

We’re sorry for the inconvenience.

Hi Mark,

We have further investigated this issue, but we’re unable to reproduce this issue or find the cause of this problem. We need a little help from your side to further investigate this issue. Can you please use the following code snippet to get the system properties and share with us?

Properties pr = System.getProperties();

TreeSet propKeys = new TreeSet(pr.keySet()); // TreeSet sorts keys

for (Iterator it = propKeys.iterator(); it.hasNext(); )


String key = (String);

System.out.println("" + key + “=” + pr.get(key) + “\n”);


We're sorry for the inconvenience and looking forward to help you out.

Hi Mark,

yet another question:
Do you use some environment where default class loader was changed ?
Do you run your code in simple Java applicaiton or do you run it on some App or Web server ?

Hi Mark,

We have released the latest version (3.4.0) of Aspose.Pdf.Kit for Java and we’re unable to notice this problem in our latest version. Could you please download it from this link and try at your end? If it still doesn’t resolve your issue then please do let us know.

We’re sorry for the inconvenience.