Hi! I´m using pdfBox 2.0.1 and i´m getting an OOM error while extracting pdf 
pages to png. 

public static List<File> pdfToImages(final InputStream pdfInputStream, final 
String imageFolderPath) {

        List<File> imageFiles = new ArrayList<File>();
        try {
            PDDocument document = null;
            try {
                document = PDDocument.load(pdfInputStream);
                String imageFormat = "." + 
ConfigurationProperty.PROXY_IMAGE_INTERNAL_TYPE.getValue();
                int dpi = 
ConfigurationProperty.PROXY_IMAGE_MAX_DPI.getIntValue();

                PDFRenderer pdfRenderer = new PDFRenderer(document);

                for (int page = 0; page < document.getNumberOfPages(); page++) {
                    BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 
dpi, ImageType.RGB);

                    String uuid = UUID.randomUUID().toString();
                    String outputPrefix = FilenameUtils.concat(imageFolderPath, 
uuid + "_pdfimg");
                    String fileName = outputPrefix + imageFormat;

                    if (ImageIOUtil.writeImage(bim, fileName, dpi)){
                        imageFiles.addAll(FileUtils.listFiles(new 
File(imageFolderPath), new PrefixFileFilter(uuid), null));
                    } else {
                        throw 
ProxyRuntimeException.of(ExceptionCodes.ERROR_GENERATING_PDF_IMAGES);
                    }
                }
            } finally {
                if (document != null) {
                    document.close();
                }
            }
        } catch (IOException e) {
            throw 
ProxyRuntimeException.of(ExceptionCodes.ERROR_GENERATING_PDF_IMAGES);
        }

        return imageFiles;
    }

I have a heap max size of 256m

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to