Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-1226

Counting pages of a PDF gives OutOfMemoryError

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Not A Problem
    • Affects Version/s: 1.6.0
    • Fix Version/s: 1.6.0
    • Component/s: Parsing, Swing GUI
    • Labels:
      None
    • Environment:
      Windows 7 / Windows XP

      Description

      I have a pdf ( 397 MB) and I am trying to count the pages.
      I am able to open the PDF with AdobeReader 9, but no with FoxitReader.
      Code:
      PDDocument doc = null;
      File temp = null;
      RandomAccessFile rand = null;
      int nr = 0;
      try

      { //create a temporary file needed by the PDFBox when dealing with PDFs really really large temp = new File("e:/temp.tmp"); //using random access file needed for PDF really large rand = new RandomAccessFile(temp,"rw"); doc = PDDocument.load(file,rand); nr = doc.getNumberOfPages(); }

      catch(Exception e)

      { e.printStackTrace(); }

      Got following exception:
      org.apache.pdfbox.exceptions.WrappedIOException
      at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:240)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1069)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1022)
      at PDFBoxExample.getHugeNrOfFiles(PDFBoxExample.java:36)
      at PDFBoxExample.main(PDFBoxExample.java:258)
      Caused by: java.lang.OutOfMemoryError: Java heap space
      at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:45)
      at java.lang.StringBuffer.<init>(StringBuffer.java:79)
      at org.apache.pdfbox.pdfparser.BaseParser.readString(BaseParser.java:1121)
      at org.apache.pdfbox.pdfparser.BaseParser.parseCOSStream(BaseParser.java:402)
      at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:552)
      at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:184)
      ... 4 more

      I attached the PDF.

        Attachments

          Activity

            People

            • Assignee:
              tboehme Timo Boehme
              Reporter:
              azapuc Anca Zapuc
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: