Claudio Acciaresi
Claudio Acciaresi

Reputation: 32351

How to extract images from pdf using Java (not using pdfbox)

I've being researching on how to extract images from a big (> 300MB) PDF file. I'm using pdfbox but for some particular reason that I can't figure out, some pages are not correctly extracted.

I'm using the PDFToImage class of pdfbox as base for my code.

So, do you know another library that may help me to do this? I know that iText may be used, but I read that it can't be used for commercial products.

I've installed the packages xpdf and xpdf-utils, and the utility called pdfimages is working perfect. But I need to solve this problem from Java and it should be portable.

Upvotes: 7

Views: 8124

Answers (3)

erjiang
erjiang

Reputation: 45657

I think you're talking about two different things here: extracting images from a PDF, and converting PDF pages to images. PDFToImage will output an image for every page, while pdfimages extracts all embedded images (e.g. a text document has 0 images).

Take a look at org.apache.pdfbox.tools.ExtractImages (source code) to see if it does what you want.

Upvotes: 7

mark stephens
mark stephens

Reputation: 3184

Have you tried icepdf or JPedal (both pure java)?

Upvotes: 0

The most likely reason why it is hard working with 300 Mb PDF's is that you run out of memory. If it works well for smaller PDF's I would have a closer look at why it fails.

Upvotes: 0

Related Questions