espresso3389 / pdfrx

pdfrx is yet another PDF viewer implementation that built on the top of PDFium. The plugin currently supports Android, iOS, Windows, macOS, Linux, and Web.
MIT License
99 stars 47 forks source link

Page flipping feature #84

Open espresso3389 opened 6 months ago

espresso3389 commented 6 months ago

Previously discussed on #71 and #83 but they're wrong place to discuss about the feature.

ezgif-5-7234ba1ecb

espresso3389 commented 6 months ago

Mmm, I'm checking the code of the page_flip plugin and found the code:

https://github.com/shivbo96/page_flip/blob/ff82dd1d3bf6693daa193447c1832d4e42c2f16e/lib/src/builders/builder.dart#L36-L47

  void _captureImage(Duration timeStamp, int index) async {
    if (_boundaryKey.currentContext == null) return;
    await Future.delayed(const Duration(milliseconds: 100));
    if (mounted) {
      final boundary = _boundaryKey.currentContext!.findRenderObject()!
          as RenderRepaintBoundary;
      final image = await boundary.toImage();
      setState(() {
        imageData[index] = image.clone();
      });
    }
  }

https://github.com/shivbo96/page_flip/blob/ff82dd1d3bf6693daa193447c1832d4e42c2f16e/lib/src/builders/builder.dart#L65-L69

        if (value == widget.pageIndex || (value == (widget.pageIndex + 1))) {
            WidgetsBinding.instance.addPostFrameCallback(
              (timeStamp) => _captureImage(timeStamp, currentPageIndex.value),
            );
          }

Basically, the plugin's behavior is unpredictable. It assumes certain delay on capturing page image.

And, further more, on the top of the code, there are several undesired global variables:

https://github.com/shivbo96/page_flip/blob/ff82dd1d3bf6693daa193447c1832d4e42c2f16e/lib/src/builders/builder.dart#L8-L11

Map<int, ui.Image?> imageData = {};
ValueNotifier<int> currentPage = ValueNotifier(-1);
ValueNotifier<Widget> currentWidget = ValueNotifier(Container());
ValueNotifier<int> currentPageIndex = ValueNotifier(0);

I think the code quality of the plugin is terrible. I think you should not use it.

espresso3389 commented 6 months ago

Anyway, PdfViewer widget won't support page flipping. It is not designed to do so and also technically impossible.

So the possible solution is to use PdfPageView with some page flipping technology... But page_flip is not good. It is completely broken and it could not be work with PdfPageView (it's not the fault of PdfPageView).

reddeath1 commented 6 months ago

Anyway, PdfViewer widget won't support page flipping. It is not designed to do so and also technically impossible.

So the possible solution is to use PdfPageView with some page flipping technology... But page_flip is not good. It is completely broken and it could not be work with PdfPageView (it's not the fault of PdfPageView).

Thank you for your response and guidance. I've noticed the same issue with the plug-in as when I used it with pdf_render: the quality of the PDF becomes very low to the extent that the content becomes unreadable. Additionally, there's no zoom functionality, and even if you implement it, the usability is not as good as what I've experienced with PdfViewer in pdfrx. Such a use case is what my readers will enjoy.

If you can by any chance suggest any plug-in for a quick win which will produce good effects like the desired flip, it would be very helpful while we wait for a native solution for pdfrx.

Thank you.

reddeath1 commented 6 months ago

Hello @espresso3389 , could you kindly take a look at this: [https://github.com/jmolins/flutboard](). -> lib/ui/flip_panel.dart What they've done is quite similar to what we want, except the flipping mechanism is vertical. However, that is an easy task to implement.

Upon inspecting the actual code, which handles the flipping, I noticed its not redrawing the pages as images on the screen, so I'm certain the quality can be retained. Now, the problem lies in being able to integrate it with pdfrx and enable pinch-to-zoom seamlessly, similar to what PdfViewer does.

espresso3389 commented 6 months ago

@reddeath1 Frankly speaking, I don't plan to implement such (actually I don't know what) feature. It is partially because I don't understand your goal. I never think page-flipping and zooming are getting along well. Do you have any realistic sketch?

reddeath1 commented 6 months ago

@reddeath1 Frankly speaking, I don't plan to implement such (actually I don't know what) feature. It is partially because I don't understand your goal. I never think page-flipping and zooming are getting along well. Do you have any realistic sketch?

Thank you again for paying attention to my requests.

The realistic sketch can be the one on this thread. The other one can be experienced on this app. I Assume your using ios but if not the app can be obtained from playstore with this name 'egazeti' https://apps.apple.com/us/app/egazeti/id1520710424

Kindly once the installation is done, kindly notify me on WhatsApp XXXXXXXXXXXX. Also, use this phone number to access the pdfs, but the auth code will be sent to that no. That is when you notify me to give you the code.

espresso3389 commented 6 months ago

Mmm, I'm just a OSS plugin developer and don't want to evaluate any such app. Futhermore, don't show your private info. on GitHub. It's public. If you show me something, please record the screen and share it here.

reddeath1 commented 4 months ago

Hi @espresso3389 I m back to this feature, do you think now it's time to kinder try and add this feature to this great plugin.? Thank you again.