简体   繁体   中英

pdf is not scaling in pdfview android

I am using library Dmitry-Borodin/pdfview-android for showing pdf in android. My view is showing pdf correctly but the scaling of pdf doesnot seems to be working.

pdfView!!.fromFile(file!!).scale(500f).show()

Above is my code for showing pdf and scaling it.

With scaling I mean that width of pdf is quite small than that of device screen width

Instead of using Library, Please go through ImageView Component.

You need to create a Bitmap that matches the aspect ratio of the Page. It's best to match the dimensions of the ImageView as well:

            PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY));
            PdfRenderer.Page page = renderer.openPage(0);
            int pageWidth = page.getWidth();
            int pageHeight = page.getHeight();
            float scale = Math.min((float) REQ_WIDTH / pageWidth, (float) REQ_HEIGHT / pageHeight);
            Bitmap bitmap = Bitmap.createBitmap((int) (pageWidth * scale), (int) (pageHeight * scale), Bitmap.Config.ARGB_8888);
            page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
            imageView.setImageBitmap(bitmap);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM