Please read the FAQ:
https://pdfbox.apache.org/2.0/faq.html#outofmemoryrrror

And update to the current version.

Tilman

Am 02.03.2017 um 13:44 schrieb Pedro Silva:
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]



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

  • OOM Pedro Silva
    • Re: OOM viraf.bankwalla
    • Re: OOM Tilman Hausherr

Reply via email to