You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Pedro Silva <pj...@gmail.com> on 2017/03/02 12:44:33 UTC

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


Re: OOM

Posted by Tilman Hausherr <TH...@t-online.de>.
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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: OOM

Posted by vi...@yahoo.com.INVALID.
You may want to see PDFBOX-3700 and Tilman's recommendation.  This worked for me.  - viraf



      From: Pedro Silva <pj...@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