pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <viraf.bankwa...@yahoo.com.INVALID>
Subject Re: OOM
Date Thu, 02 Mar 2017 13:12:42 GMT
You may want to see PDFBOX-3700 and Tilman's recommendation.  This worked for me.  - viraf



      From: Pedro Silva <pjomcs.java@gmail.com>
 To: users@pdfbox.apache.org 
 Sent: Thursday, March 2, 2017 7:44 AM
 Subject: OOM
   
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



   
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message