0

I am having Force Close in my application, when i choose a file1(size: 33,016,510 - not sure if byte or kb) but when i try a file2(size: 604,612) it does not force close. How much file size can iTextPDF can read?

file1: 400-500pages, Has Image Background and Images, but Text are all HIGHLIGHTABLE so meaning text can be READ(This is how I determine if the contents of PDF are text or images, Correct me if i am wrong).

file2: 30-50pages, has images and no background.

I have ideas why it force closes.

  1. Because of the PDF file size.
  2. The Code it self.
  3. The contents of the PDF.

The code i use to read PDF:

page_Content = PdfTextExtractor.getTextFromPage(
                    reader, 0, new SimpleTextExtractionStrategy());

What's the problem here?

Comment below if the information is lacking.

Exception:

12-26 19:20:19.026: E/AndroidRuntime(1119): FATAL EXCEPTION: main
12-26 19:20:19.026: E/AndroidRuntime(1119): java.lang.OutOfMemoryError
12-26 19:20:19.026: E/AndroidRuntime(1119):     at java.util.ArrayList.add(ArrayList.java:123)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfArray.add(PdfArray.java:269)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.readArray(PdfReader.java:1608)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.readPRObject(PdfReader.java:1657)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.readDictionary(PdfReader.java:1588)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.readPRObject(PdfReader.java:1624)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1143)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:511)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:170)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:159)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.example.panalyzerdemo.InformationRetrieval.pdfFilePath(InformationRetrieval.java:54)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.example.panalyzerdemo.MainActivity.onActivityResult(MainActivity.java:207)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.app.Activity.dispatchActivityResult(Activity.java:3890)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3514)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3560)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.app.ActivityThread.access$2800(ActivityThread.java:128)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.os.Looper.loop(Looper.java:123)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at android.app.ActivityThread.main(ActivityThread.java:4644)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at java.lang.reflect.Method.invokeNative(Native Method)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at java.lang.reflect.Method.invoke(Method.java:521)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
12-26 19:20:19.026: E/AndroidRuntime(1119):     at dalvik.system.NativeStart.main(Native Method)
Christian Eric Paran
  • 980
  • 6
  • 27
  • 49
  • 2
    You really need to find out how big the file *actually* is. There's a huge difference between trying to read a 33MB file and a 33GB file. – Jon Skeet Dec 26 '12 at 11:18
  • @JohnSkeet so you are saying that the error was in the FILE SIZE? Is there a way to read that HUGE size? – Christian Eric Paran Dec 26 '12 at 11:34
  • @JohnSkeet isnt it a 33mb? file. its 33,243kb in my explorer. – Christian Eric Paran Dec 26 '12 at 12:20
  • Also note that a PDF file typically contains many streams that are compressed. When reading them for inspection or reuse, these streams need to be decompressed. This requires much more memory. In any case: there's a 2 GB limit for old iText versions and a 2 TB limit for the latest iText versions. If you get an OutOfMemoryException, the usual cause is that you didn't provide sufficient memory. That's not an iText problem, is it? – Bruno Lowagie Dec 27 '12 at 13:14

1 Answers1

0

I have solved my problem with large PDF files. What I will do is NOT to read the whole PDF file but to read 50-100 pages first.

Christian Eric Paran
  • 980
  • 6
  • 27
  • 49
  • could you post an example of how you would you pass only 50 pages at a time through a `Reader`? – Ren Sep 28 '17 at 22:23