Coder Social home page Coder Social logo

Comments (4)

develtar avatar develtar commented on May 26, 2024

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.

from qt-pdf-viewer-library.

ic005k avatar ic005k commented on May 26, 2024

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

from qt-pdf-viewer-library.

ic005k avatar ic005k commented on May 26, 2024

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?

from qt-pdf-viewer-library.

develtar avatar develtar commented on May 26, 2024

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

from qt-pdf-viewer-library.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.