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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

There are two details.

ic005k opened this issue · comments

Hello, I have two details as follows:

  1. The APP can automatically save the location of the PDF document opened last time on the PC side, but on the Android side, it seems that it can't save the status of the document. May I ask what I missed?
  2. It seems that two-finger scaling (zoom in or out with fingers) cannot be realized on Android. How can I achieve this function?
    Thanks again.

Hi!

1- on android, the webview cannot access to the files located in the resources (.qrc), and the pdf.js library (which is located in the qrc) cannot be also accessed directly.

So, to avoid this problem, the pdf.js library folder is copied into the internal memory of the android device, which, instead, can be accessed by the webview. The viewer.html that is displayed in the screen is the one saved in that folder. On android, that folder is recreated every time the app starts the first time, for this reason you see the view is always reset. A simple solution could be:

  1. save its page number somewhere (eg. in the Settings), and set that page on pdf load
  2. load that value before showing the pdf in the onPdfLoaded. To avoid to see the animation due to the set of the page, you can delay the visibility of the page of some ms (eg. 300ms).
       property int pageFromSettings: 4   // Load page from Settings

        ....

        onPdfLoaded: {
                    // Set page from settings
                    pdfView.setPage(pageFromSettings)

                    // Pdf has been correctly loaded, ensure pdf view visibility
                    pdfView.visible = true
                    pdfView.opacity = 1
        }

2- The pinch to zoom is not supported by the webview and mouse events are managed automatically by the pdf.js library, which, if i remember correctly, doesn't support that feature on android. However, you can zoom in/out with the + or - buttons.

Thanks for your reply.
In addition, I can save the zoom value of the file, for example, 1.5. I want to restore the zoom value to 1.5 the next time I open the file. How can I do this? Including the rotation direction and the way the page is viewed, I want to restore their values the next time I open the file.
thank you

I also found a problem about thumbnail refresh, that is, after opening some large pdf files, the thumbnail cannot be refreshed, and the thumbnail of the previous file is still displayed. I wonder if this is a bug?

I want to restore the zoom value to 1.5 the next time I open the file. How can I do this? Including the rotation direction and the way the page is viewed, I want to restore their values the next time I open the file.

The methods to set those values are the following (see README for all available methods or the sample app):

  • setScrollMode(scrollMode): sets the scroll mode of the document
  • setScaleMode(scaleMode): sets the scale mode of the document
  • rotate(angle): rotates the document of the current angle
  • zoomIn(): zooms the document in
  • zoomOut(): zooms the document out

So, to update them from settings, you could do something like this:

        property var settings: ...  // Settings data

        PdfView {
            id: pdfView
            onPdfLoaded: {
                    // Pdf has been correctly loaded, now set  values from settings
                    pdfView.initFromSettings()

                    // Ensure pdf view visibility 
                    pdfView.visible = true
                    pdfView.opacity = 1
            }

            function initFromSettings() {
                    pdfView.setPage(settings["page"])
                    pdfView.setScrollMode(settings["scrollMode"])
                    pdfView.rotate(settings["rotation"])
            }
        }

Note: when using settings, remember to set organization name, domain and application name in the main.cpp, otherwise it will not save data (https://stackoverflow.com/questions/22672597/qml-qsettings-and-qml-cannot-save-load-settings).

QCoreApplication::setOrganizationName("MySoft");
QCoreApplication::setOrganizationDomain("mysoft.com");
QCoreApplication::setApplicationName("Star Runner");

I also found a problem about thumbnail refresh, that is, after opening some large pdf files, the thumbnail cannot be refreshed, and the thumbnail of the previous file is still displayed. I wonder if this is a bug?

Maybe i forgot to force the update on the thumbnails property when updated. In qml array changes are not emitted by default (unless are undefined). This weekend i'll give it a look! :D