Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. HTML to PDF converter console application

HTML to PDF converter console application

Scheduled Pinned Locked Moved Solved QtWebEngine
8 Posts 3 Posters 1.2k Views
  • 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.
  • C Offline
    C Offline
    Coder Nomad
    wrote on last edited by
    #1

    Hi,
    I am super new Qt and C++, I am a PHP web developer but I recently had a use case to utilize wkhtmltopdf to create invoice pdf from the web page. As per the repo of this tool, it is not maintained any more, and qtwebkit was the backend rendering engine. So I would like to create a simple console application using qtwebengine that can render a webpage url and convert into PDF. There is a tutorial for same available here in the qt example but this example is not available in the qt creator ( open source / community version ).

    Hence I am trying to recreate this in my Qt creator but I am confused on few things.

    1. should I select Qt Console Application if I need to create a console app, or should I still go with Qt Widgets application ?
    2. I tried with Qt Console application , in the line
    #include <QWebEnginePage>
    

    there is an error showing - : error: 'QWebEnginePage' file not found

    should I install any further dependency to satisfy this ?
    If you can give me step - by - step guide to create this simple app, please do. Any kind of guidance is greatly thankful,

    cheers

    aha_1980A 1 Reply Last reply
    0
    • C Coder Nomad

      Hi,
      I am super new Qt and C++, I am a PHP web developer but I recently had a use case to utilize wkhtmltopdf to create invoice pdf from the web page. As per the repo of this tool, it is not maintained any more, and qtwebkit was the backend rendering engine. So I would like to create a simple console application using qtwebengine that can render a webpage url and convert into PDF. There is a tutorial for same available here in the qt example but this example is not available in the qt creator ( open source / community version ).

      Hence I am trying to recreate this in my Qt creator but I am confused on few things.

      1. should I select Qt Console Application if I need to create a console app, or should I still go with Qt Widgets application ?
      2. I tried with Qt Console application , in the line
      #include <QWebEnginePage>
      

      there is an error showing - : error: 'QWebEnginePage' file not found

      should I install any further dependency to satisfy this ?
      If you can give me step - by - step guide to create this simple app, please do. Any kind of guidance is greatly thankful,

      cheers

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @Coder-Nomad,

      when you scroll down the page https://doc.qt.io/qt-6/qtwebengine-webenginewidgets-html2pdf-example.html you'll find a link example project @ code.qt.io that you can directly use.

      The reason for your problem is, that you must tell the compiler that you want to use webenginewidgets (in the Qmake or the CMake project file). Maybe it's enough to specify webengine for a console application - I don't know.

      Regards

      Qt has to stay free or it will die.

      C 1 Reply Last reply
      1
      • aha_1980A aha_1980

        Hi @Coder-Nomad,

        when you scroll down the page https://doc.qt.io/qt-6/qtwebengine-webenginewidgets-html2pdf-example.html you'll find a link example project @ code.qt.io that you can directly use.

        The reason for your problem is, that you must tell the compiler that you want to use webenginewidgets (in the Qmake or the CMake project file). Maybe it's enough to specify webengine for a console application - I don't know.

        Regards

        C Offline
        C Offline
        Coder Nomad
        wrote on last edited by Coder Nomad
        #3

        @aha_1980
        thank you for the reply. I have tried to copy the code from the repo as you suggested but below is the error I am getting. Please refer screenshot
        2745fe04-4dd2-475f-9c08-90ca5f3c3946-image.png )

        error: 'QWebEngineView' file not found

        Am I missing any libs or misconfigured path ? I am using Windows 11 and Qt Creator version 6.6

        thanks

        aha_1980A JonBJ 2 Replies Last reply
        0
        • C Coder Nomad

          @aha_1980
          thank you for the reply. I have tried to copy the code from the repo as you suggested but below is the error I am getting. Please refer screenshot
          2745fe04-4dd2-475f-9c08-90ca5f3c3946-image.png )

          error: 'QWebEngineView' file not found

          Am I missing any libs or misconfigured path ? I am using Windows 11 and Qt Creator version 6.6

          thanks

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @Coder-Nomad ,

          two things to check:

          1. Is find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) in your CMakeLists.txt?
          2. Did you even install QtWebEngine? I think it is an optional module that may not be installed by default

          Regards

          Qt has to stay free or it will die.

          C 2 Replies Last reply
          3
          • C Coder Nomad

            @aha_1980
            thank you for the reply. I have tried to copy the code from the repo as you suggested but below is the error I am getting. Please refer screenshot
            2745fe04-4dd2-475f-9c08-90ca5f3c3946-image.png )

            error: 'QWebEngineView' file not found

            Am I missing any libs or misconfigured path ? I am using Windows 11 and Qt Creator version 6.6

            thanks

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Coder-Nomad
            When you get your WebEngine stuff installed correctly, have a look at https://github.com/pwuertz/qtwehtmltopdf. (Qt5 but it's not big, doubtless can be upgraded to Qt6.) It's does just what you want. You might use it directly or copy parts of its code.

            C 1 Reply Last reply
            2
            • JonBJ JonB

              @Coder-Nomad
              When you get your WebEngine stuff installed correctly, have a look at https://github.com/pwuertz/qtwehtmltopdf. (Qt5 but it's not big, doubtless can be upgraded to Qt6.) It's does just what you want. You might use it directly or copy parts of its code.

              C Offline
              C Offline
              Coder Nomad
              wrote on last edited by Coder Nomad
              #6

              @JonB said in HTML to PDF converter console application:

              @Coder-Nomad
              When you get your WebEngine stuff installed correctly, have a look at https://github.com/pwuertz/qtwehtmltopdf. (Qt5 but it's not big, doubtless can be upgraded to Qt6.) It's does just what you want. You might use it directly or copy parts of its code.

              thank you so much for the repo - It seems exactly what I need, will try that.

              1 Reply Last reply
              0
              • aha_1980A aha_1980

                Hi @Coder-Nomad ,

                two things to check:

                1. Is find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) in your CMakeLists.txt?
                2. Did you even install QtWebEngine? I think it is an optional module that may not be installed by default

                Regards

                C Offline
                C Offline
                Coder Nomad
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • aha_1980A aha_1980

                  Hi @Coder-Nomad ,

                  two things to check:

                  1. Is find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) in your CMakeLists.txt?
                  2. Did you even install QtWebEngine? I think it is an optional module that may not be installed by default

                  Regards

                  C Offline
                  C Offline
                  Coder Nomad
                  wrote on last edited by
                  #8

                  @aha_1980 said in HTML to PDF converter console application:

                  Hi @Coder-Nomad ,

                  two things to check:

                  1. Is find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) in your CMakeLists.txt?
                  2. Did you even install QtWebEngine? I think it is an optional module that may not be installed by default

                  Regards

                  You were right, I had to install QtWebEngine, so that I could see this html2pdf from the example projects,

                  1 Reply Last reply
                  1
                  • aha_1980A aha_1980 has marked this topic as solved on

                  • Login

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