HTML to PDF converter console application
-
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.
- should I select Qt Console Application if I need to create a console app, or should I still go with Qt Widgets application ?
- 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
-
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 specifywebengine
for a console application - I don't know.Regards
-
@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
)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
-
Hi @Coder-Nomad ,
two things to check:
- Is
find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets)
in yourCMakeLists.txt
? - Did you even install QtWebEngine? I think it is an optional module that may not be installed by default
Regards
- Is
-
@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. -
@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.
-
This post is deleted!
-
@aha_1980 said in HTML to PDF converter console application:
Hi @Coder-Nomad ,
two things to check:
- Is
find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets)
in yourCMakeLists.txt
? - 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,
- Is
-