PDFBox: convert PDF to image slower than expected

I am currently using this code to convert PDF to image:

@SuppressWarnings("unchecked")
public static Image convertPDFtoImage(ByteArrayInputStream bais) {

    Image convertedImage = null;

    try {

        PDDocument document = PDDocument.load(bais);
        List<PDPage> list = document.getDocumentCatalog().getAllPages();
        PDPage page = list.get(0);

        BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 64);
        convertedImage = SwingFXUtils.toFXImage(image, null);

        document.close();

    } 
    catch (Exception e) {
        e.printStackTrace();
    }

    return convertedImage;
}

Then I show the converted image in a JavaFX ImageView sample.

In addition, I need to import these two packages until I use them:

import org.apache.commons.logging.LogFactory;
import org.apache.fontbox.afm.AFMParser;

Two questions:

  • Does it take two to three seconds to convert a simple one-page PDF file into an image where the DPI is set to 64 (which, in my opinion, is not so high)? It seems like a bit slow.
  • Why do I need these two imports until I use them? If I do not import them, I get a lot of errors and the conversion does not work.

PDF JavaFX, - - . PDF JavaFX ( ) .

!

+4

All Articles