Generate PDF page thumbnails in Android
With PDFViewCtrl, you can get a thumbnail Bitmap image for each page in a PDF document.
The following example request thumbnail for page 3:
pdfViewCtrl.addThumbAsyncListener(new PDFViewCtrl.ThumbAsyncListener() {
@Override
public void onThumbReceived(int page, int[] buf, int width, int height) {
try {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(buf, 0, width, 0, 0, width, height);
// use the bitmap
} catch (OutOfMemoryError oom) {
// error
}
}
});
// request thumbnail for page 3
pdfViewCtrl.getThumbAsync(3);pdfViewCtrl.addThumbAsyncListener(object:PDFViewCtrl.ThumbAsyncListener() {
fun onThumbReceived(page:Int, buf:IntArray, width:Int, height:Int) {
try {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).apply {
this.setPixels(buf, 0, width, 0, 0, width, height)
}
} catch (oom:OutOfMemoryError) {
// error
}
}
})
// request thumbnail for page 3
pdfViewCtrl.getThumbAsync(3)where pdfViewCtrl is an instance of PDFViewCtrl.
Last updated
Was this helpful?