4

I'm working on a project where I need to display PDF content inside our application. I'm trying to use PdfRenderer of Android API. For now, I'm able to show a pdf page as bitmap and move between all other pages.

But I don't understand how to implement zoom on a page. I mean I know how to zoom an image, but for pdf it needs to be recalculated at every zoom level (such as tile ?). On zoom I need to recalculate Bitmap with correct Rect and Matrix I guess, that's the point I'm missing.

Does some one has already done this or similar ?

PS: I want to make it by my own but feel free to send me opensource library thanks

  • 1
    "I need to display PDF content inside our application" -- unless those PDFs are created by you and guaranteed to work with `PdfRenderer`, `PdfRenderer` is a poor choice, as it will fail to render many PDF files. Use [something else](https://commonsware.com/blog/2017/01/04/options-viewing-pdfs.html). – CommonsWare Dec 18 '17 at 13:31
  • We manage our own pdf, and some of them are AES encrypted. This is why I need to use my own pdf viewer. The only thing i'm not able to do is the zoom rendering .. – Nicolas Demoisson Dec 18 '17 at 13:46
  • "This is why I need to use my own pdf viewer" -- that does not make `PdfRenderer` a good choice, when compared to other in-process solutions, such as [those that I linked to in my previous comment](https://commonsware.com/blog/2017/01/04/options-viewing-pdfs.html). But, FWIW, [this sample app](https://github.com/commonsguy/cw-omnibus/tree/v8.8/PDF/PdfRenderer) demonstrates using `SubsamplingScaleImageView` with `PdfRenderer` for pinch-zoom capability. – CommonsWare Dec 18 '17 at 13:49
  • This is working, but it's not a good solution. I need to give bigger image if I want a nice zoom. It's not zooming and re-rendering image from pdf of visible page – Nicolas Demoisson Dec 18 '17 at 15:26
  • And this library isn't compatible with pre-Lollipop devices – Nicolas Demoisson Dec 18 '17 at 16:09
  • `SubsamplingScaleImageView` works back to API Level 14. `PdfRenderer` is only available for API Level 21+. – CommonsWare Dec 18 '17 at 16:11
  • @CommonsWare, does "this sample app" grant the functionality that a multipage PDF can be scrolled from top to bottom, for ex by adding a scrollview wrapper? If not, any suggestion for that? – carl Sep 09 '21 at 15:45
  • @carl: "does "this sample app" grant the functionality that a multipage PDF can be scrolled from top to bottom, for ex by adding a scrollview wrapper?" -- no, it uses a `ViewPager`. The whole sample is about 200 lines of Java code. "If not, any suggestion for that?" -- possibly `ViewPager2`, since it supports vertical pages. – CommonsWare Sep 09 '21 at 16:47
  • 1
    @commonsware: Afterwards, I was thinking that perhaps a RecyclerView.Adapter without any ornaments or padding would be a good solution, i.e. that all pages are launched into its own viewholder. Should work. But I reverted to HTML, which I should have done from the start, so problems solved. – carl Sep 10 '21 at 17:18
  • @carl: "I was thinking that perhaps a RecyclerView.Adapter without any ornaments or padding would be a good solution, i.e. that all pages are launched into its own viewholder" -- that too would work (and `ViewPager2` is built on `RecyclerView`). "But I reverted to HTML" -- yeah, `WebView` is way easier, if you're in position to back away slowly from PDF. – CommonsWare Sep 10 '21 at 17:23

0 Answers0