Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML show PDF file
Forum Updated to NodeBB v4.3 + New Features

QML show PDF file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
28 Posts 6 Posters 6.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Melle_87
    wrote on last edited by Melle_87
    #1

    Hi all,
    what is the easiest way to show PDF files in a qml application?
    I use Qt5.12.4 and I cross compile my application on Ubuntu to run it on raspberry pi 4 with raspbian buster lite.
    Does anyone have tipps or an example?

    Kind regards

    1 Reply Last reply
    0
    • artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by artwaw
      #2

      Hi,
      to render PDF into anything showable (image that can be displayed with QLabel) you need to either use QPDF module (that requires QtWebEngine module) or use external library (I can recommend Poppler, does the job and is simple as can be, has Qt5 wrapper included).
      First one is GPL or paid, other one GPL.
      There are also other external libraries available, both paid and Open Source, but from what I saw Poppler is simpler than any.

      EDIT: corrected wrong module name.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      0
      • artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        Let me add that for QML you'd need to wrap rendering into C++ backend, I am not aware of any direct method to use with QML (but then again, I am no expert in QML).

        For more information please re-read.

        Kind Regards,
        Artur

        M 1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

          You can use poppler as I show in this post: https://stackoverflow.com/a/52844509/6622587

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          M 1 Reply Last reply
          1
          • artwawA artwaw

            Let me add that for QML you'd need to wrap rendering into C++ backend, I am not aware of any direct method to use with QML (but then again, I am no expert in QML).

            M Offline
            M Offline
            Melle_87
            wrote on last edited by
            #5

            @artwaw: Thank you. I will try Poppler.

            M 1 Reply Last reply
            0
            • M Melle_87

              @artwaw: Thank you. I will try Poppler.

              M Offline
              M Offline
              Melle_87
              wrote on last edited by Melle_87
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • eyllanescE eyllanesc

                You can use poppler as I show in this post: https://stackoverflow.com/a/52844509/6622587

                M Offline
                M Offline
                Melle_87
                wrote on last edited by
                #7

                @eyllanesc: Ok. Thank you for the example. I compiled and installed the plugin. But why is it "import org.docviewer.poppler 1.0"?
                This gives me the error "module "org.docviewer.poppler" is not installed".
                Maybe I should mention that I am cross compiling on Ubuntu my application for raspberry pi.

                jsulmJ 1 Reply Last reply
                0
                • M Melle_87

                  @eyllanesc: Ok. Thank you for the example. I compiled and installed the plugin. But why is it "import org.docviewer.poppler 1.0"?
                  This gives me the error "module "org.docviewer.poppler" is not installed".
                  Maybe I should mention that I am cross compiling on Ubuntu my application for raspberry pi.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Melle_87 said in QML show PDF file:

                  But why is it "import org.docviewer.poppler 1.0"?

                  Well, because you need to import Poppler stuff if you want to use it.
                  "I compiled and installed the plugin" - did you cross-compiled it for your device or host machine?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Melle_87 said in QML show PDF file:

                    But why is it "import org.docviewer.poppler 1.0"?

                    Well, because you need to import Poppler stuff if you want to use it.
                    "I compiled and installed the plugin" - did you cross-compiled it for your device or host machine?

                    M Offline
                    M Offline
                    Melle_87
                    wrote on last edited by
                    #9

                    @jsulm: At the moment I am a little bit confused.
                    I compiled and installed it directly on my raspberry.

                    jsulmJ 1 Reply Last reply
                    0
                    • M Melle_87

                      @jsulm: At the moment I am a little bit confused.
                      I compiled and installed it directly on my raspberry.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Melle_87 said in QML show PDF file:

                      I compiled and installed it directly on my raspberry

                      It needs to be in your sysroot. Did you resync your sysroot after installing on RPi?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      M 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Melle_87 said in QML show PDF file:

                        I compiled and installed it directly on my raspberry

                        It needs to be in your sysroot. Did you resync your sysroot after installing on RPi?

                        M Offline
                        M Offline
                        Melle_87
                        wrote on last edited by
                        #11

                        @jsulm: Ah okay. Of course, I have to resync my sysroot. I resynced the folders /usr/local/include, /usr/local/lib and /usr/lib/arm-linux-gnueabihf/qt5 from raspberry to host.

                        Then I added this to my qmldir file:

                        module org.docviewer.poppler
                        PDFView 1.0 PDFView.qml
                        plugin popplerPlugin
                        typeinfo popplerPlugin.qmltypes
                        

                        But now I get the error message:

                        plugin "popplerPlugin" not found
                        

                        What is the reason for this error message?

                        jsulmJ 1 Reply Last reply
                        0
                        • M Melle_87

                          @jsulm: Ah okay. Of course, I have to resync my sysroot. I resynced the folders /usr/local/include, /usr/local/lib and /usr/lib/arm-linux-gnueabihf/qt5 from raspberry to host.

                          Then I added this to my qmldir file:

                          module org.docviewer.poppler
                          PDFView 1.0 PDFView.qml
                          plugin popplerPlugin
                          typeinfo popplerPlugin.qmltypes
                          

                          But now I get the error message:

                          plugin "popplerPlugin" not found
                          

                          What is the reason for this error message?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Melle_87 I'm not a QML expert.
                          Not sure you have to change qmldir.
                          When you installed Poppler on RPi - where was it installed?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          M 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Melle_87 I'm not a QML expert.
                            Not sure you have to change qmldir.
                            When you installed Poppler on RPi - where was it installed?

                            M Offline
                            M Offline
                            Melle_87
                            wrote on last edited by
                            #13

                            @jsulm: I think on raspi it was installed in /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Because in this folder I find popplerPlugin.qmltypes.

                            KroMignonK jsulmJ 2 Replies Last reply
                            0
                            • M Melle_87

                              @jsulm: I think on raspi it was installed in /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Because in this folder I find popplerPlugin.qmltypes.

                              KroMignonK Offline
                              KroMignonK Offline
                              KroMignon
                              wrote on last edited by
                              #14

                              @Melle_87 said in QML show PDF file:

                              think on raspi it was installed in /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Because in this folder I find popplerPlugin.qmltypes.

                              You can follow the import process when setting environment variable QML_IMPORT_TRACE.
                              As written in documentation, QML import path is:

                              Additional import paths can be added through QQmlEngine::addImportPath() or the QML2_IMPORT_PATH environment variable. When running the qmlscene tool, you can also use the -I option to add an import path.

                              Take a look here ==> https://doc.qt.io/qt-5/qtqml-syntax-imports.html#qml-import-path

                              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                              M 1 Reply Last reply
                              1
                              • M Melle_87

                                @jsulm: I think on raspi it was installed in /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Because in this folder I find popplerPlugin.qmltypes.

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @Melle_87 Does it work if you do not change qmldir?

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                M 1 Reply Last reply
                                0
                                • KroMignonK KroMignon

                                  @Melle_87 said in QML show PDF file:

                                  think on raspi it was installed in /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Because in this folder I find popplerPlugin.qmltypes.

                                  You can follow the import process when setting environment variable QML_IMPORT_TRACE.
                                  As written in documentation, QML import path is:

                                  Additional import paths can be added through QQmlEngine::addImportPath() or the QML2_IMPORT_PATH environment variable. When running the qmlscene tool, you can also use the -I option to add an import path.

                                  Take a look here ==> https://doc.qt.io/qt-5/qtqml-syntax-imports.html#qml-import-path

                                  M Offline
                                  M Offline
                                  Melle_87
                                  wrote on last edited by
                                  #16

                                  @KroMignon: Thank you. So it is possible to set this QML2_IMPORT_PATH variable in Qt Creator in the Run Environment? I set this variable to /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Is this correct?

                                  KroMignonK 1 Reply Last reply
                                  0
                                  • jsulmJ jsulm

                                    @Melle_87 Does it work if you do not change qmldir?

                                    M Offline
                                    M Offline
                                    Melle_87
                                    wrote on last edited by
                                    #17

                                    @jsulm: If I don't change the qmldir file I get "module "org.docviewer.poppler" is not installed".

                                    1 Reply Last reply
                                    0
                                    • M Melle_87

                                      @KroMignon: Thank you. So it is possible to set this QML2_IMPORT_PATH variable in Qt Creator in the Run Environment? I set this variable to /usr/lib/arm-linux-gnueabihf/qt5/qml/org/docviewer/poppler. Is this correct?

                                      KroMignonK Offline
                                      KroMignonK Offline
                                      KroMignon
                                      wrote on last edited by KroMignon
                                      #18

                                      @Melle_87 said in QML show PDF file:

                                      So it is possible to set this QML2_IMPORT_PATH variable in Qt Creator in the Run Environment?

                                      Yes, I think so. But I would suggest you first to try out QML_IMPORT_TRACE to be aware why your plugin in not loaded.
                                      Perhaps there are missing libs?
                                      ==> https://doc.qt.io/qt-5/qtquick-debugging.html#debugging-module-imports

                                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                      M 1 Reply Last reply
                                      0
                                      • KroMignonK KroMignon

                                        @Melle_87 said in QML show PDF file:

                                        So it is possible to set this QML2_IMPORT_PATH variable in Qt Creator in the Run Environment?

                                        Yes, I think so. But I would suggest you first to try out QML_IMPORT_TRACE to be aware why your plugin in not loaded.
                                        Perhaps there are missing libs?
                                        ==> https://doc.qt.io/qt-5/qtquick-debugging.html#debugging-module-imports

                                        M Offline
                                        M Offline
                                        Melle_87
                                        wrote on last edited by Melle_87
                                        #19

                                        @KroMignon: Thank for alle the tipps. I leave my qmldir file as it is and only set QML2_IMPORT_PATH = /usr/lib/arm-linux-gnueabihf/qt5/qml. Now the everything seems to be loaded correctly.
                                        But now I have a new problem. On start up I get a "Segmentation fault".
                                        I think the problem is that I compiled poppler with qmake of Qt 5.11.3. But actually I use Qt5.12.4. I have both Qt versions on the raspi. How can I explicitly use the qmake of Qt5.12.4 for compiling poppler?

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • M Melle_87

                                          @KroMignon: Thank for alle the tipps. I leave my qmldir file as it is and only set QML2_IMPORT_PATH = /usr/lib/arm-linux-gnueabihf/qt5/qml. Now the everything seems to be loaded correctly.
                                          But now I have a new problem. On start up I get a "Segmentation fault".
                                          I think the problem is that I compiled poppler with qmake of Qt 5.11.3. But actually I use Qt5.12.4. I have both Qt versions on the raspi. How can I explicitly use the qmake of Qt5.12.4 for compiling poppler?

                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          @Melle_87 said in QML show PDF file:

                                          How can I explicitly use the qmake of Qt5.12.4 for compiling poppler?

                                          By calling the qmake from the Qt version you want to use (use absolute path to qmake).

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          M 1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved