Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zooming inside a large PDF file crashes on Android #26

Closed
Maniae opened this issue Sep 25, 2024 · 2 comments
Closed

Zooming inside a large PDF file crashes on Android #26

Maniae opened this issue Sep 25, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Maniae
Copy link

Maniae commented Sep 25, 2024

  • How did you link to the library (autolinking, manual, rn link, cocoapods)?
    Autolinking

  • What version of React Native?
    0.74.5

  • What version of the library?
    1.3.2

  • iOS/Android version?
    Android 13

  • Did the problem happen after updating React Native?
    No

  • Are you using the library for the first time?
    Yes

On Android, zooming inside a large/complex PDF file (over ~6Mo) causes the app to crash:

java.lang.RuntimeException: Canvas: trying to draw too large(134806560bytes) bitmap.
android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
android.widget.ImageView.onDraw(ImageView.java:1449)
android.view.View.draw(View.java:23351)
android.view.View.updateDisplayListIfDirty(View.java:22210)
android.view.View.draw(View.java:23076)
android.view.ViewGroup.drawChild(ViewGroup.java:4544)
androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5545)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
com.github.douglasjunior.reactNativePdfRenderer.modules.PdfRendererRecyclerView.dispatchDraw(PdfRendererRecyclerView.java:156)

EDIT : This doesn't crash on version 1.2.0 (But the pdf rendering is kinda blurry)

@douglasjunior
Copy link
Owner

This is because now the Bitmap is created by multiplying the zoom scale:

Math.round(page.getWidth() * newZoom),
Math.round(page.getHeight() * newZoom),

The best solution would be to crop the canvas to only the visible area, but this could be complex to handle when the user navigates within the zoomed area.

For now, you can limit the zoom to a level that doesn't cause a crash.

@douglasjunior douglasjunior added help wanted Extra attention is needed bug Something isn't working labels Sep 26, 2024
@douglasjunior
Copy link
Owner

douglasjunior commented Sep 26, 2024

Android has a limitation on Bitmap size when rendering to a canvas: : https://stackoverflow.com/search?q=java.lang.RuntimeException%3A+Canvas%3A+trying+to+draw+too+large

To quickly solve this, I added a prop maxPageResolution to limit the page resolution when zooming on Android.

Available in version 1.4.0: https://github.com/douglasjunior/react-native-pdf-renderer/releases/tag/1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants