jblough / Android-Pdf-Viewer-Library

DEPRECATED - Pdf Viewer library for Android
656 stars 329 forks source link

BufferUnderflowException in Xperia Devices and Nexus 4 Devices plus Distortion in rendering pdf pages when jumping to a random page #29

Open tusharsappal opened 10 years ago

tusharsappal commented 10 years ago

Hi, I am using your library to render pdf files , I see BufferUnderFlowException in logcat in some of the sony Xperia devices, moreover when I manually jump to a random page , the contents sometimes are not rendered properly , any particular cause ?

Here's the logcat snapshot

05-05 16:31:53.765: D/OpenGLRenderer(15005): Enabling debug mode 0 05-05 16:31:56.908: I/PDFVIEWER(15005): onCreate 05-05 16:31:56.908: E/PDFVIEWER(15005): restoreInstance 05-05 16:31:56.978: I/PDFVIEWER(15005): Intent { cmp=com.granthi.mgranthi/com.tusharsappal.granthi.mgranthi.Second (has extras) } 05-05 16:31:56.988: I/PDFVIEWER(15005): ST='file '/storage/sdcard0/Android/data/com.granthi.mgranthi/files/Sukhmani-Sahib-Gurumukhi.pdf' has 133524 bytes' 05-05 16:31:57.028: I/PDFVIEWER(15005): ST='Anzahl Seiten:78' 05-05 16:31:57.048: I/PDFVIEWER(15005): ST='reading page 1, zoom:1.0' 05-05 16:32:00.562: I/PDFVIEWER(15005): ST='reading page 1, zoom:1.5' 05-05 16:32:01.824: I/PDFVIEWER(15005): ST='reading page 1, zoom:1.0' 05-05 16:32:02.594: I/PDFVIEWER(15005): ST='reading page 1, zoom:0.6666667' 05-05 16:32:03.385: I/PDFVIEWER(15005): ST='reading page 1, zoom:1.0' 05-05 16:32:04.146: I/PDFVIEWER(15005): ST='reading page 2, zoom:1.0' 05-05 16:32:04.206: D/dalvikvm(15005): GC_CONCURRENT freed 5494K, 45% free 7057K/12816K, paused 3ms+30ms, total 97ms 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): cmd='Tf:null 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): java.nio.BufferUnderflowException 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at java.nio.Buffer.checkGetBounds(Buffer.java:177) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:41) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at java.nio.MappedByteBufferAdapter.get(MappedByteBufferAdapter.java:144) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at java.nio.ByteBuffer.get(ByteBuffer.java:384) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.nio.NioByteBuffer.get(NioByteBuffer.java:99) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.decode.FlateDecode.decode(FlateDecode.java:68) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.decode.PDFDecoder.decodeStream(PDFDecoder.java:92) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFObject.decodeStream(PDFObject.java:334) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFObject.getStreamBuffer(PDFObject.java:307) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFObject.getStreamBuffer(PDFObject.java:304) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.font.TTFFont.(TTFFont.java:80) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.font.PDFFont.getFont(PDFFont.java:165) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFParser.getFontFrom(PDFParser.java:1349) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFParser.iterate(PDFParser.java:848) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.execute(BaseWatchable.java:263) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.go(BaseWatchable.java:197) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFFile.getPage(PDFFile.java:1589) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.showPage(PdfViewerActivity.java:779) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.access$12(PdfViewerActivity.java:769) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity$3.run(PdfViewerActivity.java:259) 05-05 16:32:04.236: E/ANDPDF.pdfparser(15005): at java.lang.Thread.run(Thread.java:856) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): cmd='Tj:null 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): java.lang.NullPointerException 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFTextFormat.doTextNormal(PDFTextFormat.java:324) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFTextFormat.doText(PDFTextFormat.java:271) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFParser.iterate(PDFParser.java:884) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.execute(BaseWatchable.java:263) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.go(BaseWatchable.java:197) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFFile.getPage(PDFFile.java:1589) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.showPage(PdfViewerActivity.java:779) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.access$12(PdfViewerActivity.java:769) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity$3.run(PdfViewerActivity.java:259) 05-05 16:32:04.266: E/ANDPDF.pdfparser(15005): at java.lang.Thread.run(Thread.java:856) 05-05 16:32:09.071: I/PDFVIEWER(15005): ST='reading page 2, zoom:1.5' 05-05 16:32:09.121: D/dalvikvm(15005): GC_FOR_ALLOC freed 1820K, 47% free 6879K/12816K, paused 34ms, total 46ms 05-05 16:32:09.121: I/dalvikvm-heap(15005): Grow heap (frag case) to 10.994MB for 2181184-byte allocation 05-05 16:32:09.211: D/dalvikvm(15005): GC_CONCURRENT freed 101K, 31% free 8926K/12816K, paused 6ms+14ms, total 84ms 05-05 16:32:23.617: I/PDFVIEWER(15005): ST='reading page 10, zoom:1.5' 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): cmd='Tf:null 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): java.nio.BufferUnderflowException 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at java.nio.Buffer.checkGetBounds(Buffer.java:177) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:41) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at java.nio.MappedByteBufferAdapter.get(MappedByteBufferAdapter.java:144) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at java.nio.ByteBuffer.get(ByteBuffer.java:384) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.nio.NioByteBuffer.get(NioByteBuffer.java:99) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.decode.FlateDecode.decode(FlateDecode.java:68) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.decode.PDFDecoder.decodeStream(PDFDecoder.java:92) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFObject.decodeStream(PDFObject.java:334) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFObject.getStreamBuffer(PDFObject.java:307) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFObject.getStreamBuffer(PDFObject.java:304) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.font.TTFFont.(TTFFont.java:80) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.font.PDFFont.getFont(PDFFont.java:165) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFParser.getFontFrom(PDFParser.java:1349) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFParser.iterate(PDFParser.java:848) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.execute(BaseWatchable.java:263) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.go(BaseWatchable.java:197) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFFile.getPage(PDFFile.java:1589) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.showPage(PdfViewerActivity.java:779) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.access$12(PdfViewerActivity.java:769) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity$3.run(PdfViewerActivity.java:259) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at java.lang.Thread.run(Thread.java:856) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): cmd='Tj:null 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): java.lang.NullPointerException 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFTextFormat.doTextNormal(PDFTextFormat.java:324) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFTextFormat.doText(PDFTextFormat.java:271) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFParser.iterate(PDFParser.java:884) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.execute(BaseWatchable.java:263) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.BaseWatchable.go(BaseWatchable.java:197) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at com.sun.pdfview.PDFFile.getPage(PDFFile.java:1589) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.showPage(PdfViewerActivity.java:779) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity.access$12(PdfViewerActivity.java:769) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at net.sf.andpdf.pdfviewer.PdfViewerActivity$3.run(PdfViewerActivity.java:259) 05-05 16:32:23.697: E/ANDPDF.pdfparser(15005): at java.lang.Thread.run(Thread.java:856) 05-05 16:32:23.867: D/dalvikvm(15005): GC_FOR_ALLOC freed 1734K, 36% free 8276K/12816K, paused 28ms, total 28ms 05-05 16:32:23.877: I/dalvikvm-heap(15005): Grow heap (frag case) to 12.359MB for 2181184-byte allocation 05-05 16:32:23.917: D/dalvikvm(15005): GC_CONCURRENT freed 75K, 31% free 10340K/14948K, paused 3ms+6ms, total 41ms 05-05 16:32:24.047: W/IInputConnectionWrapper(15005): finishComposingText on inactive InputConnection 05-05 16:32:24.047: W/IInputConnectionWrapper(15005): finishComposingText on inactive InputConnection 05-05 16:32:27.711: I/PDFVIEWER(15005): ST='reading page 10, zoom:1.0' 05-05 16:32:33.718: I/PDFVIEWER(15005): ST='reading page 9, zoom:1.0' 05-05 16:32:33.998: D/dalvikvm(15005): GC_CONCURRENT freed 5084K, 44% free 7218K/12820K, paused 4ms+11ms, total 43ms 05-05 16:32:33.998: D/dalvikvm(15005): WAIT_FOR_CONCURRENT_GC blocked 9ms

ndorigatti commented 10 years ago

hi, probably you did not the "fix", that is mentioned in issue #14 (in particular my comment https://github.com/jblough/Android-Pdf-Viewer-Library/issues/14#issuecomment-14949800) or #10

I'm keeping a fork of this (and others) projects and i will merge some of the changes/updates in order to have a working (almost) version of the library

tusharsappal commented 10 years ago

Thanks when can we expect a patch from your end fixing the issue

ndorigatti commented 10 years ago

unfortunately it is a long process, I was not on github when i started working on that and I've changed almost all files, but i have to manually merge them. Try this fix for now.

tusharsappal commented 10 years ago

the fix in issue#14 mentions that changes are in 1) https://github.com/preichelt/Android-Pdf-Viewer-Library/blob/master/src/com/sun/pdfview/decode/FlateDecode.java

and also in another comment i see some changes to be done in

PDFImage.java:

in which file I need to do it finally

tusharsappal commented 10 years ago

or the one done in PDFImage.parseData()

else if (colorSpace.getType() == PDFColorSpace.COLORSPACE_RGB) { int maxH = getHeight(); int maxW = getWidth(); bi = Bitmap.createBitmap(maxW, maxH, imgBytes.length == 2 * maxW * maxH ? Config.RGB_565 : Config.ARGB_8888); try { bi.copyPixelsFromBuffer(ByteBuffer.wrap(imgBytes)); } catch (Exception e) { int[] line = new int[maxW]; int n = 0; for (int h = 0; h < maxH; h++) { for (int w = 0; w < getWidth(); w++) { line[w] = ((0xff & (int) imgBytes[n]) << 8 | (0xff & (int) imgBytes[n + 1])) << 8 | (0xff & (int) imgBytes[n + 2]) | 0xFF000000; n += 3; } bi.setPixels(line, 0, maxW, 0, h, maxW, 1); } }

ndorigatti commented 10 years ago

The comment linked tells the fix to FlatDecode (which is your issue if you look at logcat). The fix for PDFImage is if you see badly drawings in pictures inside PDF. You should do both fixes, but the second one is not related to your logcat.

tusharsappal commented 10 years ago

:+1: will try and will update you thanks

tusharsappal commented 10 years ago

Building the jar locally was not successful at my end , @ndorigatti could you please make the changes that would fix the buffer under flow exception and compile the code to build the latest jar and please publish that jar to github

tusharsappal commented 10 years ago

Moreover I was wondering how I can add Zoming in when the user taps the Pdf page (I know that the PDF file gets converted into image, so how can I ensure that the PDF page gets zoomed in when tapped )

tusharsappal commented 10 years ago

@jblough please help with the above issue it would be great :)

BYogesh commented 10 years ago

While Opening the PDF file it gets corrupt in kitkat os but works on Gingerbread ? Please suggest...what to do ?

ndorigatti commented 10 years ago

@BYogesh what do you mean corrupt? images are corrupt or also text?

BYogesh commented 10 years ago

The PDF shows screenshot_2014-06-03-15-34-46

ndorigatti commented 10 years ago

can you provide a screenshot of that?

BYogesh commented 10 years ago

@ndorigatti i have attached ...

ndorigatti commented 10 years ago

mmm seems to be a problem of wrong image format... Is the origin pdf a sort of table?

tusharsappal commented 10 years ago

@BYogesh what mentioned is also occurring at my end for nexus 4 devices having Kitkat , but it happens only when we jump to a random page number and not traverse the pages in a sequential order

BYogesh commented 10 years ago

@tusharsappal @ndorigatti ...Its original pdf and i am going to first page itself

tusharsappal commented 10 years ago

@BYogesh can you please provide the logcat ,and yes thats interesting traversing the pdfs sequentially didn't caused issue at my end anyways logcat details would be very helpful in the case

ndorigatti commented 10 years ago

it would be ideal to check if the problem is on the viewer or on the "exporter". It should be good to write a simple test application that given the file and the page number, allows to export a specific page to file (i have a sort of this on an old project somewhere).

BYogesh commented 10 years ago

But It Works for gingerbread...Perfectly without any issues. Is there any other such library that can help ...Pls suggest

tusharsappal commented 10 years ago

@ndorigatti now you are active on the issue , I have one query do you have an updated code with changes mentioned in the issues earlier , I tried with the changes but I was not able to build the jar. Moreover I was also wondering how can I handle zoom by double tapping and to swap the pages ??? any Ideas

tusharsappal commented 10 years ago

reopened the issue

BYogesh commented 10 years ago

@tusharsappal

log1pic

ndorigatti commented 10 years ago

The logcat does not seem to have anything really useful. I'm not active on the code since I don't have the time to make the changes, I have a personal fork of a new version but i did not tested it (needs a lot of refactoring). About the problem on kitkat, the code must be checked and it's a long thing to do, you should try in debug mode

BYogesh commented 10 years ago

@ndorigatti ..ok ..thanks a lot ...can i get your fork link...if possible.!

ndorigatti commented 10 years ago

go to my profile, i dont have lot of repos, you can find it!

tusharsappal commented 10 years ago

Thanks @ndorigatti I will try and will update you about the new code :)

ndorigatti commented 10 years ago

@tusharsappal and @BYogesh I've finished merging the code on my repo and tryed yesterday with a genymotion emulated kitkat device and the image was created correctly. you can find my repo at: https://github.com/ndorigatti/Android-Pdf-Viewer-Library

Please if you have issue for THAT library, post there. If you want to code, pull request THERE, i will not continuosly check this jblough repo since it is not maintained anymore.