Saturday Sep 01, 2012

PDF to Image Conversion in Java

In the past, I created a NetBeans plugin for loading images as slides into NetBeans IDE. That means you had to manually create an image from each slide first. So, this time, I took it a step further. You can choose a PDF file, which is then automatically converted to an image for each page, each of which is presented as a node that can be clicked to open the slide in the main window.

As you can see, the remaining problem is font rendering. Currently I'm using PDFBox. Any alternatives that render font better?

This is the createKeys method of the child factory, ideally it would be replaced by code from some other library that handles font rendering better:

protected boolean createKeys(List<ImageObject> list) {
    mylist = new ArrayList<ImageObject>();
    try {
        if (file != null) {
            ProgressHandle handle = ProgressHandleFactory.createHandle(
                    "Creating images from " + file.getPath());
            PDDocument document = PDDocument.load(file);
            List<PDPage> pages = document.getDocumentCatalog().getAllPages();
                PDPage pDPage = pages.get(i);
                mylist.add(new ImageObject(pDPage.convertToImage(), i));
    } catch (IOException ex) {
    return true;

The import statements from PDFBox are as follows:

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;




« September 2012 »