Skip to content

When sliding through the PDF file, closing the current page causes the app to crash. #830

Closed

Description

@LJW123

What react-native version are you using?
0.72.4
What react-native-pdf version are you using?
6.7.5
What platform does your issue occur on? (android/ios/both)
android
Describe your issue as precisely as possible :

  1. When sliding through the PDF file, closing the current page causes the app to crash. The crash details are as follows:

E FATAL EXCEPTION: PDF renderer
Process: com.sssss, PID: 12594
java.lang.IllegalStateException: Already closed
at io.legere.pdfiumandroid.util.ConfigKt.handleAlreadyClosed(Config.kt:20)
at io.legere.pdfiumandroid.PdfPage.close(PdfPage.kt:582)
at kotlin.io.CloseableKt.closeFinally(Closeable.kt:56)
at io.legere.pdfiumandroid.PdfiumCore.renderPageBitmap(PdfiumCore.kt:406)
at com.github.barteksc.pdfviewer.PdfFile.renderPageBitmap(PdfFile.java:301)
at com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:109)
at com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:66)
at android.os.Handler.dispatchMessage(Handler.java:117)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:293)
at android.os.HandlerThread.run(HandlerThread.java:110)

image

Show us the code you are using?
return (

{fileUri && (
<Pdf
trustAllCerts={false}
style={styles.pdfStyle}
source={getFileSource()}
onLoadComplete={(numberOfPages, filePath) => {
console.log(Number of pages: ${numberOfPages});
}}
onPageChanged={(page, numberOfPages) => {
console.log(Current page: ${page});
}}
onError={error => {
console.error(error);
}}
/>
)}

);

Activity

  1. nguyentitan commented on May 9, 2024

    @nguyentitan

    I'm facing the same issue, any suggestion?

  2. dipteshdx commented on May 9, 2024

    @dipteshdx

    I am facing the same issue any solution?

  3. tsalama commented on May 15, 2024

    @tsalama

    Also facing this, but a different error:

    java.lang.RuntimeException: Loaded page is null
      io.legere.pdfiumandroid.PdfDocument.nativeLoadPage(Native Method)
      io.legere.pdfiumandroid.PdfDocument.openPage(PdfDocument.kt:83)
      io.legere.pdfiumandroid.PdfiumCore.renderPageBitmap(PdfiumCore.kt:406)
      com.github.barteksc.pdfviewer.PdfFile.renderPageBitmap(PdfFile.java:301)
      com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:109)
      com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:66)
      android.os.Handler.dispatchMessage(Handler.java:106)
      android.os.Looper.loopOnce(Looper.java:201)
      android.os.Looper.loop(Looper.java:288)
      android.os.HandlerThread.run(HandlerThread.java:67)
    
  4. huanguolin commented on May 27, 2024

    @huanguolin

    same issue here.

  5. huanguolin commented on May 27, 2024

    @huanguolin

    my workaround: downgrade from 6.7.5 to 6.6.2.

  6. nguyentitan commented on May 27, 2024

    @nguyentitan

    I have temporary solution to fix it, hope this issue will be fixed ASAP.

    1. Downgrade to 6.7.4
    2. Create patch file from our project and apply the fix from this PR: Fix app crash with this.lastRNBFTask.cancel is not a function #827
    3. re-run npm install to apply the patch, crash issue resolved.
  7. jlopezdominguez commented on May 29, 2024

    @jlopezdominguez

    Having the same problem here, and also this one :

    Fatal Exception: java.lang.RuntimeException: Get page pdf document null
    at io.legere.pdfiumandroid.PdfDocument.nativeLoadPage(PdfDocument.kt)
    at io.legere.pdfiumandroid.PdfDocument.openPage(PdfDocument.kt:83)
    at io.legere.pdfiumandroid.PdfiumCore.renderPageBitmap(PdfiumCore.kt:406)
    at com.github.barteksc.pdfviewer.PdfFile.renderPageBitmap(PdfFile.java:301)
    at com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:109)
    at com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:66)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.os.HandlerThread.run(HandlerThread.java:65)

    Any clue on how to fix this ?

  8. agungjk commented on May 29, 2024

    @agungjk

    my workaround: downgrade from 6.7.5 to 6.6.2.

    tested, working on my project

  9. TraFost commented on Jun 24, 2024

    @TraFost

    does u guys facing an error while the component finished loading and then the app suddenly crashed? i've been searching for this and got no answer

  10. EwaGuziejko commented on Aug 6, 2024

    @EwaGuziejko

    Any idea how to fix this one? For me the "already closed" issue is raised when user enters pdf screen and then goes to other place in the app - when he comes back to pdf the app crashes with this error.

  11. basit-nbs commented on Aug 19, 2024

    @basit-nbs

    Is their any solution available for this? I cannot see any potential fix to this currently. Also, downgrading the version does not seems like a fix to this error.

  12. Dzmitry-Klokau commented on Sep 5, 2024

    @Dzmitry-Klokau

    downgrade to 6.6.2 works for me

  13. irmakcosarsahna commented on Sep 24, 2024

    @irmakcosarsahna

    I have the same problem. It started happening on Android devices after updating the React Native version and the package.

    "react-native": "^0.75.2",
    "react-native-pdf": "^6.7.5",

  14. jay4008 commented on Sep 28, 2024

    @jay4008

    Hi @tsalama
    are you able to solve the issue

  15. tsalama commented on Sep 28, 2024

    @tsalama

    @jay4008 Yes but only by downgrading to 6.7.3

  16. 13 remaining items

  17. augusthjerrild commented on Feb 28, 2025

    @augusthjerrild

    I downgraded to version 6.7.3, and the issue was resolved, but the author released version 6.7.7 thirteen days ago, and I haven't tried it.

    It's still crashing in 6.7.7, so no need to close this yet. It's still an ongoing issue that hopefully should be fixed asap? :-)

  18. my-srd commented on Mar 6, 2025

    @my-srd

    ฉันลดรุ่นลงเป็นเวอร์ชั่น 6.7.3 และปัญหาได้รับการแก้ไขแล้ว แต่ผู้เขียนได้เปิดตัวเวอร์ชั่น 6.7.7 เมื่อสิบสามวันที่แล้ว และฉันยังไม่ได้ลองเลย

    เวอร์ชัน 6.7.7 ยังคงมีปัญหาอยู่ ดังนั้นไม่จำเป็นต้องปิดปัญหานี้เลย ปัญหานี้ยังคงมีอยู่และหวังว่าจะได้รับการแก้ไขโดยเร็วที่สุด :-)

    me too.

  19. skbaji6 commented on Mar 17, 2025

    @skbaji6

    How come it is closed? we are still facing the issue.

  20. VimukthiShohan commented on Mar 19, 2025

    @VimukthiShohan

    It's still crashing in 6.7.7

  21. guihendias commented on May 6, 2025

    @guihendias

    We have over 20 crashes daily due to this error

  22. gonca-gul commented on May 7, 2025

    @gonca-gul

    Unfortunately, if I downgrade to 6.7.2, I cannot open iOS links. I applied a patch to open links on 6.7.6. But I am having an Android crash problem with 6.7.6.

  23. pallav110 commented on Jul 24, 2025

    @pallav110

    We would need a solution , because of this i can't build my enterprise app , which has a core functionality of showing pdf.

  24. EdwardvanRaak commented on Aug 19, 2025

    @EdwardvanRaak

    @wonday
    This library is currently using com.github.zacharee:AndroidPdfViewer:4.0.1

    implementation 'com.github.zacharee:AndroidPdfViewer:4.0.1'

    The fix from r0b0t3d is in 4.0.2

    https://github.com/zacharee/AndroidPdfViewer/blob/master/CHANGELOG.md#402

    So this react-native-pdf library is simply 1 version behind the fix. A single line of code and a re-release is needed to help out these devs (nobody wants to contribute a PR apparently).

    In the meantime:

    If you don't want to bother, just fork/patch the repo for now, or you could probably just hack this in your Android Application class as well by ignoring the crash with a global uncaught exception handler.

    override fun onCreate() {
            super.onCreate()
    
            val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
    
            Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
                if (throwable is IllegalStateException && throwable.message?.contains("Already closed") == true) {
                    // Do nothing
                } else {
                    defaultHandler?.uncaughtException(thread, throwable)
                }
            }
        }

    Don't copy paste the above code, just wondering if it works in this case.

  25. YOEL311 commented on Sep 17, 2025

    @YOEL311

    @wonday This library is currently using com.github.zacharee:AndroidPdfViewer:4.0.1

    react-native-pdf/android/build.gradle

    Line 127 in d49cb92

    implementation 'com.github.zacharee:AndroidPdfViewer:4.0.1'
    The fix from r0b0t3d is in 4.0.2

    https://github.com/zacharee/AndroidPdfViewer/blob/master/CHANGELOG.md#402

    So this react-native-pdf library is simply 1 version behind the fix. A single line of code and a re-release is needed to help out these devs (nobody wants to contribute a PR apparently).

    In the meantime:

    If you don't want to bother, just fork/patch the repo for now, or you could probably just hack this in your Android Application class as well by ignoring the crash with a global uncaught exception handler.

    override fun onCreate() {
    super.onCreate()

        val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
    
        Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
            if (throwable is IllegalStateException && throwable.message?.contains("Already closed") == true) {
                // Do nothing
            } else {
                defaultHandler?.uncaughtException(thread, throwable)
            }
        }
    }
    

    Don't copy paste the above code, just wondering if it works in this case.

    I can't use the 4.0.2 version
    is not exist in nvm

    https://mvnrepository.com/artifact/com.github.zacharee/AndroidPdfViewer
    I see only the 4.0.1 version

    How can we use the 4.0.2 version?

  26. Prajwaltechversant commented on Oct 8, 2025

    @Prajwaltechversant

    +1

  27. maneesh-techversant commented on Oct 9, 2025

    @maneesh-techversant

    In the latest version 7.0.0, the same issue is still reproducing.

  28. DragomirAndrei19 commented on Oct 9, 2025

    @DragomirAndrei19

    Sentry reports the same error for me.

  29. yakupozbaydar commented on Nov 17, 2025

    @yakupozbaydar

    experiencing on production.any updates?

  30. Natanaelvich commented on Dec 10, 2025

    @Natanaelvich

    I migrated the PDF viewing implementation to https://github.com/126punith/react-native-pdf-jsi, and since then I have not encountered this crash anymore. It seems the issue is resolved with this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions