2

I want to displaythe thumb images of pdf in my app. I am using this answer. But I don't know how to use it in android as Rectangle2D can't be userd in java. I tried using RectFand modified the code as:

 File file = new File(arrayOfResults.get(arg0).filePath);
 RandomAccessFile raf = new RandomAccessFile(file, "r");
                FileChannel channel = raf.getChannel();
                ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
                        0, channel.size());
                PDFFile pdffile = new PDFFile(buf);

                // draw the first page to an image
                PDFPage page = pdffile.getPage(0);

                // get the width and height for the doc at the default zoom
                RectF rect = new RectF(0, 0, (int) page.getWidth(),
                        (int) page.getHeight());

But the app crashed with the following error:

java.lang.NoClassDefFoundError: java.awt.geom.Rectangle2D$Double
at com.sun.pdfview.PDFFile.parseNormalisedRectangle(PDFFile.java:1874)

Please help.

Community
  • 1
  • 1
berserk
  • 2,690
  • 3
  • 32
  • 63

2 Answers2

5

Android added a PdfRenderer class that can do that in API 21.

If you need to go below that, you need to ship with your own PDF render engine. We've looked at the marketplaces and found that the options are all lacking in one way or another, and created PSPDFKit for Android. It's a commercial PDF framework and (full disclaimer) I'm part of the team that builds it.

In PSPDFKit for Android, you can use renderPageToBitmap to render the PDF into a bitmap.

steipete
  • 7,581
  • 5
  • 47
  • 81
1

If your project is personal or you are an indie, try http://plugpdf.com/ They offer their Android PDF SDK free for you. You can also check out their blog article about rendering a PDF page to bitmap image on Android. http://plugpdf.com/how-to-render-a-pdf-document-to-bitmap-image-on-android/

Disclaimer: I am the Founder & CEO at ePapyrus Inc. which runs plugpdf.com.

user3892
  • 127
  • 1
  • 4
  • Actually I dont want to view the whole pdf.. i just want to generate a bitmap from it to show as thumbnail :) – berserk May 09 '14 at 13:21
  • Yes, you can use plugpdf exactly for your purpose. If you render a PDF page to a small bitmap, it is a thumbnail. :-) http://plugpdf.com/how-to-render-a-pdf-document-to-bitmap-image-on-android/ – user3892 May 09 '14 at 13:44