Limitations on opening pdf file in Android

前端 未结 6 1492
暗喜
暗喜 2021-02-11 15:04

I am trying to opening some pdf from my Android application. I am using an Intent for doing that:

Intent intent = new Intent();
intent.setDataAndType(Uri.parse(u         


        
6条回答
  •  梦谈多话
    2021-02-11 15:43

    If API >=21 you can use PDFRenderer to create a bitmap of each page, but its only viewable, not editable. Here is an example i made up on the fly, lacking navigation buttons, but those shouldn't be to hard to implement.

    PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(new File("/path/to/file.pdf"), 
                ParcelFileDescriptor.MODE_READ_ONLY));
        PdfRenderer.Page page = renderer.openPage(0);
        Bitmap bitmap = Bitmap.createBitmap(page.getWidth(), page.getHeight(),
                Bitmap.Config.ARGB_8888);
        page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
        imageView.setImageBitmap(bitmap);
        page.close();
        renderer.close();
    

    Edit

    PdfRenderer requires a local file for the FileDescriptor. So in turn viewing through the "cloud", to my knowledge, isnt possible with this approach.

提交回复
热议问题