2012-01-23 54 views
0

我在android平臺上使用itext閱讀pdf,我使用下面的代碼。但是當我嘗試打開大pdf時,它在第一行發出內存錯誤,例如reader =新的PdfReader(fileName);。下面是單擊大文件時生成的斜線軌跡。無法從大pdf中提取tex

 reader = new PdfReader(fileName);   
    numberOfPages = reader.getNumberOfPages(); 
    System.out.println("This document contains:" + numberOfPages); 
    extractor = new PdfTextExtractor(reader); 

    01-23 18:04:50.607: INFO/System.out(428): @@@@!!!/sdcard/Moby_Dick_NT.pdf 

external 899K/1038K, paused 202ms 
    01-23 18:05:31.298: INFO/dalvikvm(428): Jit: resizing JitTable from 1024 to 2048 
    01-23 18:05:32.947: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1678K, 31% free 10361K/14855K, external 899K/1038K, paused 218ms 
    01-23 18:05:35.657: DEBUG/dalvikvm(428): GC_CONCURRENT freed 2038K, 31% free 10403K/15047K, external 899K/1038K, paused 5ms+10ms 

    01-23 18:06:00.537: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1845K, 30% free 10625K/15111K, external 899K/1038K, paused 9ms+8ms 
    01-23 18:06:02.397: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1995K, 32% free 10546K/15303K, external 899K/1038K, paused 259ms 
    01-23 18:06:04.518: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1993K, 32% free 10545K/15303K, external 899K/1038K, paused 9ms+5ms 
    01-23 18:06:06.468: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1917K, 31% free 10583K/15303K, external 899K/1038K, paused 9ms+5ms 
    01-23 18:06:08.008: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.145MB to 16.000MB 
    01-23 18:06:08.008: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1542K, 29% free 10981K/15303K, external 899K/1038K, paused 9ms+5ms 
    browse.com/.PDFView} 
    01-23 18:06:09.338: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.498MB to 16.000MB 
    01-23 18:06:09.338: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1370K, 27% free 11342K/15495K, external 899K/1038K, paused 243ms 
    01-23 18:06:10.437: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.776MB to 16.000MB 
    01-23 18:06:10.437: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1079K, 25% free 11627K/15495K, external 899K/1038K, paused 228ms 
    01-23 18:06:10.857: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.841MB to 16.000MB 
    01-23 18:06:10.857: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 256K, 25% free 11694K/15495K, external 899K/1038K, paused 215ms 
    01-23 18:06:10.867: INFO/dalvikvm-heap(428): Forcing collection of SoftReferences for 4100-byte allocation 
    01-23 18:06:11.137: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.827MB to 16.000MB 
    01-23 18:06:11.137: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 15K, 25% free 11679K/15495K, external 899K/1038K, paused 272ms 
    01-23 18:06:11.137: ERROR/dalvikvm-heap(428): Out of memory on a 4100-byte allocation. 
    01-23 18:06:11.147: INFO/dalvikvm(428): "main" prio=5 tid=1 RUNNABLE 
    01-23 18:06:11.147: INFO/dalvikvm(428): | group="main" sCount=0 dsCount=0 obj=0x4001f1a8 self=0xce48 

回答

1

還有另一個線程關於內存分配的相關討論,在這裏SO:

Android memory allocation

還沒有嘗試過自己,但它可能是值得嘗試的選擇

android:largeHeap="true" 

自清單打開16MB的上限。

+0

但是支持16MB堆大小的手機呢? – Rookie

+1

如果他們只支持16MB?狡猾,那麼人們將不得不依次讀取文件,同時保持內存中的部分內容,以便它永遠不會碰到16MB的邊界。不知道如何做到這一點。 – Scalarr