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

PdfDocumentReference is disposed too aggressively / PdfViewer should support viewing a PdfDocument. #36

Closed
jezell opened this issue Jan 19, 2024 · 2 comments

Comments

@jezell
Copy link

jezell commented Jan 19, 2024

If you have a PdfDocument in memory, there is not a good way to use it with the PdfViewer.

PdfViewer should support direct rendering a PdfDocument rather than forcing the use of a PdfDocumentRef + PdfStore.

You can use the PdfStore.load method to return a PdfDocument as a PdfDocumentRef, but the magic dispose of PdfDocumentRef will get in the way and prevent you from reusing the PdfDocument:

  @override
  void removeListener(VoidCallback listener) {
    _listeners.remove(listener);
    if (_listeners.isEmpty) {
      dispose();
    }
  }

As soon as the viewer disposes, the reference will dispose itself, breaking the PdfDocument. Dispose should not be automatically called by the removeListener call, the reference should only be disposed when dispose is called manually. If you use PdfStore.load to try to manage the lifecycle of the document on your own, this forces you to add a dummy listener just to prevent it from being disposed if you need to reuse the reference later.

@espresso3389
Copy link
Owner

#37 is anyway fixed.

Basically, PdfDocumentRef is introduced to keep the "same" instance between password trials (without valid password, PdfDocument cannot be obtained). If we do that without such mechanism, it's very difficult to deal with async PdfDocument creation process with password trials.

Anyaway, for your purpose, I just added PdfViewer.documentRef that directly accepts PdfDocumentRef.

espresso3389 added a commit that referenced this issue Jan 20, 2024
@espresso3389
Copy link
Owner

PdfViewer.documentRef will be removed on the next release. I realized that the primary constructor has the completely same signature to it :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants