develtar / qt-pdf-viewer-library

The qt-pdf-viewer-library is a qml wrapper of pdf.js library which allows you to render PDF files in a WebView. This library also works on Android devices, and it uses WebSocketServer, WebSocketTransport and WebChannel to exchange data between qml and the browser environment.
Apache License 2.0
41 stars 9 forks source link

A question about opening a new file. #3

Closed ic005k closed 1 year ago

ic005k commented 1 year ago

Hello, in one of my project (https://github.com/ic005k/Knot) integrates the library, but found a problem, is to open the second or more files, there will be a blank, during normal open it again. At the moment, I get around this problem by opening an empty file before opening one, but I don't think this is a scientific solution. What do you think about that? thank you.

pdfView.load("") pdfView.load(pdfPath)

https://github.com/ic005k/Knot/blob/e19e5ceed53f8bc9e3a3d1f19588e1cb159640ea/pdf_module/PdfPage.qml#L35

ic005k commented 1 year ago

If you're interested, download the Knot and try it out. Open the pdf file under "Reader." In the meantime, any suggestions and corrections are welcome. Thank you.

pdfpic

develtar commented 1 year ago

At the moment i cannot try it, but below some suggestions:

this,

       ...
       onViewerLoaded: {

            isViewEnd = true

            pdfView.load(pdfPath)
            pdfView.visible = true         // <-- call this before pdfView.load()
            console.debug("onViewerLoaded......  " + isViewEnd)
        }

should become:

       ...
       onViewerLoaded: {

            isViewEnd = true

            pdfView.visible = true
            pdfView.load(pdfPath)

            console.debug("onViewerLoaded......  " + isViewEnd)
        }

Note that setting the visibility of the WebView, will cause the reload of the WebView. The load of pdf is asynchronous, so multiple calls to the load method could cause issues.

ic005k commented 1 year ago
  • I see that in your you called : this is not necessary, because it is already initialized by the (see ). Multiple WebView's initializations could cause issues.main.cpp``QtWebView::initialize();``QtPdfViewerInitializer``qtpdfviewerinitializer.cpp

That's the question. Thank you very much. Remove QtWebView::initialize(); , everything is fine.

ic005k commented 1 year ago

In addition, pdf.js seems to have a new version, I don't know if you have any plans to upgrade them, I am looking forward to it, thank you.

In my opinion, this is QML's best pdf solution for Android right now.

https://github.com/mozilla/pdf.js/releases/tag/v3.1.81

develtar commented 1 year ago

Remove QtWebView::initialize(); , everything is fine

Perfect! Then i consider the issue closed :D

In addition, pdf.js seems to have a new version, I don't know if you have any plans to upgrade them, I am looking forward to it, thank you.

Nope, i haven't any plan to upgrade it to the new version: lots of work would be needed to support older qt versions and android devices. Furthermore, some changes on pdf.js source files were needed to correctly emit signals and capture errors.

In my opinion, this is QML's best pdf solution for Android right now

Thank you! I really appreciate it! :D