2

I googled, but I cannot find a solution to do this.

I am in need of showing an image thumbnail view from a PDF's first page without opening it. The PDF file will be available in my mobile itself.

Installing another external library is not possible. Mupdf is available.

Jota
  • 17,281
  • 7
  • 63
  • 93

2 Answers2

2

Finally i done this, by,

drawPage(bp, 0, size.x, size.y, 0, 0, size.x, size.y, new Cookie());

it'll help you to render first page of PDF as BitMap. This method implemented in MuPDFCore.java.

PointF pageSize = getPageSize(0); float mSourceScale = Math.max(w/pageSize.x, h/pageSize.y);

        Point size = new Point((int)(pageSize.x*mSourceScale), (int)(pageSize.y*mSourceScale));
        final Bitmap bp = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);

        drawPage(bp, 0, size.x, size.y, 0, 0, size.x, size.y, new Cookie());
        storeImageIntoLocal(bp,filePath);//To Do my custom method to store bitmap into local
1

If you want to do this without muPDF, have a look at How to convert a PDF page to an image in Android?. The second answer gives a link to PdfRenderer (available from API 21). You probably use it like this:

 // create a new renderer
 PdfRenderer renderer = new PdfRenderer(getSeekableFileDescriptor());

 // render the page
 Page page = renderer.openPage(i).render(mBitmap, null, null, Page.RENDER_MODE_FOR_DISPLAY);

 // do stuff with the bitmap

 // close the page
 page.close();

 // close the renderer
 renderer.close();
Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188