syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.46k stars 680 forks source link

PdfViewerPlugin.closeDocument (pdfviewer_plugin.dart:154) #817

Closed DivyamDh closed 3 months ago

DivyamDh commented 1 year ago
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError
PlatformException(error, Current page not closed, null, java.lang.IllegalStateException: Current page not closed at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:293) at 
android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:205) at g.f.a.a.c.a(SyncfusionFlutterPdfViewerPlugin.java:1) at 
g.f.a.a.c.onMethodCall(SyncfusionFlutterPdfViewerPlugin.java:4) at i.a.d.a.k$a.a(MethodChannel.java:2) at 
io.flutter.embedding.engine.f.e.k(DartMessenger.java:2) at io.flutter.embedding.engine.f.e.l(DartMessenger.java:2) at 
io.flutter.embedding.engine.f.e.m(Unknown Source:0) at io.flutter.embedding.engine.f.c.run(Unknown Source:12) at 
android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at 
android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8653) at 
java.lang.reflect.Method.invoke(Native Method) at 
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) ). Error thrown null.

Getting this exception for a couple of users. No idea what is really causing it. Can someone please guide us ?

deepika134 commented 1 year ago

Hi DivyamDh,

We tried to reproduce the reported issue with provided details, but the PDF is loaded properly without any exception on our end. For your reference, we have prepared the sample and it can be downloaded from the following link, https://www.syncfusion.com/downloads/support/directtrac/general/ze/github1201699423.zip

If you still reproduce the reported issue in your use case, then kindly share the modified issue reproducing in sample and also, please share the following details, to reproduce the reported issue on our end.

  1. Platforms in which the issue is reproduced (Android, iOS, Web, macOS).
  2. Device Specification.
  3. Flutter Doctor log.
  4. syncfusion_flutter_pdfviewer package version.
  5. Flutter SDK version. 6.Issue reproducing steps.

This information will be helpful for us to provide you a prompt solution at the earliest.

Regards, Deepika Ravi

ductranit commented 1 year ago

hi @deepika134 , I got the same error on firebase crashlytics, but I still can't reproduce on my devices (even with your sample).

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Current page not closed, null, java.lang.IllegalStateException: Current page not closed
    at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:269)
    at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:184)
    at com.syncfusion.flutter.pdfviewer.e.a(Unknown Source:13)
    at com.syncfusion.flutter.pdfviewer.e.onMethodCall(Unknown Source:83)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Unknown Source:17)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(Unknown Source:18)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(Unknown Source:20)
    at io.flutter.embedding.engine.dart.DartMessenger.a(Unknown Source:0)
    at io.flutter.embedding.engine.dart.a.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:7025)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
). Error thrown null.
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:653)
       at MethodChannel._invokeMethod(platform_channel.dart:296)
       at PdfViewerPlugin.closeDocument(pdfviewer_plugin.dart:154)
  1. Platform: android 8, 9, 10, 11, 12
  2. There are a lot of reported android devices

Galaxy J7+ Galaxy Tab A (2016) Galaxy S21+ 5G Galaxy Note20 Ultra 5G POCO F3 Redmi 9 OnePlus 8 5G Redmi 9C

  1. flutter doctor
    [✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale en-VN)
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2021.3)
    [✓] VS Code (version 1.64.0)
    [✓] VS Code (version 1.73.0)
    [✓] Connected device (2 available)
    [✓] HTTP Host Availability
  2. syncfusion_flutter_pdfviewer: ^20.3.52
  3. flutter 3.3.7
  4. Not able to reproduce
TimYusR commented 1 year ago

Having similar issue, reported in firebase crashlytics

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Current page not closed, null, java.lang.IllegalStateException: Current page not closed
    at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:269)
    at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:184)
    at bg.c.a(Unknown Source:13)
    at bg.c.onMethodCall(Unknown Source:83)
    at eh.k$a.a(Unknown Source:17)
    at rg.c.l(Unknown Source:18)
    at rg.c.m(Unknown Source:20)
    at rg.c.h(Unknown Source:0)
    at rg.b.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6647)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
). Error thrown null.
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:653)
       at MethodChannel._invokeMethod(platform_channel.dart:296)
       at PdfViewerPlugin.closeDocument(pdfviewer_plugin.dart:154)

Platform: Android 8.1 Device: moto e5 go

[✓] Flutter (Channel stable, 3.3.1, on macOS 12.4 21F79 darwin-x64, locale en-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

syncfusion_flutter_pdfviewer: ^20.2.44-beta

Can't reproduce either.

Will be glad to know if there are any updates on that issue.

ricardoboss commented 1 year ago

Can I help in some way?

dsingh06 commented 1 year ago

+1 for this error. It is showing on Firebase, same as above.

deepika134 commented 1 year ago

Kindly refer the following KB link for load a PDF document from the Firebase storage, https://www.syncfusion.com/kb/12757/how-to-load-a-pdf-document-from-firebase-storage-in-syncfusion-flutter-pdfviewer

victordf commented 1 year ago

Same error, reported in crashlytics

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Current page not closed, null, java.lang.IllegalStateException: Current page not closed
    at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:269)
    at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:184)
    at na.c.a(Unknown Source:15)
    at na.c.onMethodCall(Unknown Source:83)
    at tb.l$a.a(Unknown Source:17)
    at gb.c.l(Unknown Source:18)
    at gb.c.m(Unknown Source:20)
    at gb.c.i(Unknown Source:0)
    at gb.b.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:7000)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
). Error thrown null.
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:653)
       at MethodChannel._invokeMethod(platform_channel.dart:296)
       at PdfViewerPlugin.closeDocument(pdfviewer_plugin.dart:154)
[√] Flutter (Channel stable, 3.3.9, on Microsoft Windows [versÆo 10.0.22621.1105], locale pt-BR)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.4)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.3)
[√] VS Code (version 1.74.3)
[√] Connected device (4 available)
[√] HTTP Host Availability

syncfusion_flutter_pdfviewer: ^20.4.38

myselfuser1 commented 1 year ago

This will help https://www.youtube.com/watch?v=gAUVz0U7eyA

POGTAAP commented 1 year ago

syncfusion_flutter_pdfviewer: ^21.1.41

I have the same error but it comes random

Any idea?

deepika134 commented 1 year ago

Hi @POGTAAP ,

We tried to reproduce the reported issue with provided details, but the PDF is loaded properly without any exception on our end. For your reference, we have prepared the sample and it can be downloaded from the attachment. If you still reproduce the reported issue in your use case, then kindly share the modified issue reproducing in sample and also, please share the following details, to reproduce the reported issue on our end.

sample_github817.zip

This information will be helpful for us to provide you a prompt solution at the earliest.

tanzirulnayan commented 1 year ago

I'm experiencing an exception in syncfusion_flutter_pdfviewer 21.2.4 The pdf viewer is used inside showGeneralDialog. The exception is thrown when the dialog is colsed.

The exception is logged below:

Exception has occurred.
PlatformException (PlatformException(error, Current page not closed, null, java.lang.IllegalStateException: Current page not closed
    at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:278)
    at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:190)
    at com.syncfusion.flutter.pdfviewer.SyncfusionFlutterPdfViewerPlugin.closeDocument(SyncfusionFlutterPdfViewerPlugin.java:229)
    at com.syncfusion.flutter.pdfviewer.SyncfusionFlutterPdfViewerPlugin.onMethodCall(SyncfusionFlutterPdfViewerPlugin.java:99)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
))

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.7.9, on Microsoft Windows [Version 10.0.19045.2130], locale en-US)
This is taking an unexpectedly long time...[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.19)
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.69.2)
[√] Proxy Configuration
[√] Connected device (4 available)
[√] HTTP Host Availability

• No issues found!
sarbogast commented 8 months ago

Did anyone find a solution to this one? Because I have the same problem that randomly pops up for me and it crashes my app. I don't even know how to swallow that exception to avoid the crash.

For now, the only solution I could find was to fork the plugin and add a catch block for IllegalStateException in SyncfusionFlutterPdfViewerPlugin.java:

  @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  boolean closeDocument(String documentID) {
    try {
      Objects.requireNonNull(documentRepo.get(documentID)).renderer.close();
      Objects.requireNonNull(documentRepo.get(documentID)).fileDescriptor.close();
      documentRepo.remove(documentID);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    }
    return true;
  }
herbertamukhuma commented 7 months ago

This is how to replicate it.

  1. Assume you have two screens (HomeScreen and PdfScreen)
  2. You push the pdf screen and provide it with a pdf file.
  3. Next, pop back to the home page
  4. If you proceed to push the PDF screen with a different pdf file, you will have the error described above
deepika134 commented 7 months ago

We tried to replicate the reported issue with provided details, but the PDF loaded properly without any exception on our side. For your reference, we have attached the sample and included a screen recording of the output, which can be downloaded from the attachment. Please review the shared sample. If the issue still occurs on your end, kindly provide us with the modified issue replicating sample. This will be helpful for us to provide prompt solution at earliest. Sample.zip

sarbogast commented 7 months ago

It is obviously complicated to replicate but the android documentation for this method says that it can throw this exception that you don't catch. So why not coding defensively and actually catch that exception to prevent it from bubbling up?

ramkumarsync commented 3 months ago

We are closing this issue since we don't have enough information to reproduce it. You can reopen this anytime and share the proper issue reproducing sample and the details to proceed further.