Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mupdf Generate Thumbnail

Tags:

android

mupdf

I implemented E-Book App using Mupdf Library and want to generate thumbnail for each pdf file in my project Could Anyone tell me how to generate This? Thanks in advance

like image 285
Bibo Wagdy Avatar asked Jan 27 '26 15:01

Bibo Wagdy


2 Answers

In Librelio they're using the old version of project muPDF without Cookie. In new versions you need to extend mu pdf core, like this:

class MuPDFThumb extends MuPDFCore{
    public MuPDFThumb(Context context, String filename) throws Exception{
        super(context, filename);
    }

    public Bitmap thumbOfFirstPage(int w, int h){
        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());
        return bp;
    }
}

You need to extends, because Cookie is an internal class of MuPDFCore and it is required for calling drawPage.

The method thumbOfFirstPage takes 2 arguments: width and height of the ImageView to fill with bitmap:

thumbnailImageView.setImageBitmap(bPGenerated) in UIThread

like image 187
ldd Avatar answered Jan 30 '26 03:01

ldd


Try the following:

core.drawPage(bm, page, pageW, pageH, patchX, patchY, patchW, patchH);
like image 43
user2589629 Avatar answered Jan 30 '26 03:01

user2589629



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!