PdfRendering zoom on page
Asked Answered
P

0

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

Phony answered 18/12, 2017 at 13:25 Comment(10)
"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.Cicala
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 ..Phony
"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. But, FWIW, this sample app demonstrates using SubsamplingScaleImageView with PdfRenderer for pinch-zoom capability.Cicala
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 pagePhony
And this library isn't compatible with pre-Lollipop devicesPhony
SubsamplingScaleImageView works back to API Level 14. PdfRenderer is only available for API Level 21+.Cicala
@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?Grassi
@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.Cicala
@commonsware: Afterwards, I was thinking that perhaps a RecyclerView.Adapter<Adapter.ViewHolder> 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.Grassi
@carl: "I was thinking that perhaps a RecyclerView.Adapter<Adapter.ViewHolder> 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.Cicala

© 2022 - 2024 — McMap. All rights reserved.