Jump to content

QtPDF Build Instructions: Difference between revisions

From Qt Wiki
Shawnrutledge (talk | contribs)
Created page with "QtPDF is provided via [https://marketplace.qt.io/products/qtpdf Marketplace] for convenience; but you can also build it yourself from the qtwebengine repo. <code> $ git clone..."
 
WindJunkie (talk | contribs)
added details about using "qt-configure-module"
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
QtPDF is provided via [https://marketplace.qt.io/products/qtpdf Marketplace] for convenience; but you can also build it yourself from the qtwebengine repo.
[https://doc.qt.io/qt-6/qtpdf-index.html Qt PDF] binaries are available from the Qt installer under "Extensions"; but here's how to build it yourself.


<code>
In case of any issues, please open a bug report for the [https://qt-project.atlassian.net/issues/?jql=project%20%3D%20%22QTBUG%22%20AND%20component%20%3D%20%22PDF%22 PDF component at Qt Bug Reports].
 
==Building from git with an existing Qt 6==
 
This step requires an existing Qt 6 installation.
 
* Install html5lib: hopefully your system package manager provides a python3-html5lib package; alternatively:
 
$ pip3 install html5lib
 
* Sources for the Qt PDF module are hosted within QtWebEngine repository. Clone and initialize the git repository (currently about 7.1 GB):
(Commercial Qt customers are advised to use their own access to the source code on git. See the page [[Getting Commercial Qt Sources]] for more details)<pre>
$ git clone https://code.qt.io/qt/qtwebengine.git
$ git clone https://code.qt.io/qt/qtwebengine.git
$ cd qtwebengine
$ cd qtwebengine
$ git checkout 6.12 (or whatever version)
$ git submodule update --init --recursive
$ git submodule update --init --recursive
$ qmake . -- -no-build-qtwebengine-core
</pre>
Info: creating stash file /home/myname/dev/qtwebengine/.qmake.stash
 
Info: creating cache file /home/myname/dev/qtwebengine/.qmake.cache
* Fortunately build of QtWebEngine itself is not necessary for Qt PDF. Qt PDF uses just PDFium as a part of Chromium inside the QtWebEngine. Configure a shadow build:
 
<pre>
$ mkdir build
$ cd build
$ <path to the "bin" folder in your Qt 6 installation>/qt-configure-module ../qtwebengine -- -DQT_FEATURE_qtwebengine_build=OFF
</pre>
 
* Build Qt PDF
 
<pre>
$ cmake --build . --parallel
</pre>
 
* Install Qt PDF
 
<pre>
$ cmake --install .
</pre>
 
This will install Qt PDF into the Qt 6 installation you specified and used above.
 
Test the new build with one of the examples provided by Qt PDF. See folders examples/pdf and examples/pdfwidgets.
 
==Building from source installed with the installer==
 
In Qt Maintenance Tool (AKA the installer) you can choose Extensions | Qt PDF | Qt 6.xx.x | Desktop to get the already-built version, and/or Extensions | Qt WebEngine | Qt 6.xx.x | Sources to get the source code for Qt WebEngine and Qt PDF together.


Running configuration tests...
*configure a shadow build
Checking for architecture supported... yes
... (many more tests)
Done running configuration tests.


Configure summary:  
<pre>
$ cd ~/Qt/6.12.0/Src/qtwebengine (or whatever version)
$ mkdir build
$ cd build
$ <path to the "bin" folder of this Qt>/qt-configure-module .. -- -DQT_FEATURE_qtwebengine_build=OFF
...
-- Configuration summary has been written to /home/username/Qt/6.12.0/Src/qtwebengine/build/config.summary
...
-- Configuring done (14.0s)
-- Generating done (0.1s)
-- Build files have been written to: /home/username/Qt/6.12.0/Src/qtwebengine/build


Qt WebEngine Build Tools:
$ cat config.summary
   Use System Ninja ....................... yes
WebEngine Repository Build Options:
  Use System Gn .......................... no
   Build Gn ............................... yes
  Jumbo Build Merge Limit ................ 8
  Jumbo Build ............................ yes
   Developer build ........................ no
   Developer build ........................ no
   QtWebEngine required system libraries:
   Build with rust ........................ no
    fontconfig ........................... yes
  Use precompiled headers for 3rdparty ... no
    dbus ................................. yes
   Build QtWebEngine Modules:
    nss .................................. yes
     Build QtWebEngineCore ................ no
    khr .................................. yes
     Build QtWebEngineWidgets ............. no
    glibc ................................ yes
     Build QtWebEngineQuick ............... no
   QtWebEngine required system libraries for qpa-xcb:
  Build QtPdf Modules:
     x11 .................................. yes
     Build QtPdfWidgets ................... yes
     libdrm ............................... yes
     Build QtPdfQuick ..................... yes
     xcomposite ........................... yes
   Optional system libraries:
    xcursor .............................. yes
     re2 .................................. no
     xi ................................... yes
     xtst ................................. yes
   Optional system libraries used:
     re2 .................................. yes
     icu .................................. no
     icu .................................. no
     libwebp, libwebpmux and libwebpdemux . yes
     libwebp, libwebpmux and libwebpdemux . yes
     opus ................................. yes
     opus ................................. yes
     ffmpeg ............................... no
     ffmpeg ............................... no
     libvpx ............................... yes
     libvpx ............................... no
     snappy ............................... yes
     snappy ............................... yes
     glib ................................. yes
     glib ................................. yes
     zlib ................................. yes
     zlib ................................. yes
     minizip .............................. yes
     minizip .............................. yes
    libevent ............................. yes
    jsoncpp .............................. yes
    protobuf ............................. yes
     libxml2 and libxslt .................. yes
     libxml2 and libxslt .................. yes
     lcms2 ................................ yes
     lcms2 ................................ yes
     png .................................. yes
     png .................................. no
     JPEG ................................. yes
    tiff ................................. yes
     harfbuzz ............................. yes
     jpeg ................................. no
    libopenjpeg2 ......................... yes
     harfbuzz ............................. no
     freetype ............................. yes
     freetype ............................. yes
     xkbcommon ............................ yes
     libpci ............................... yes
    libudev .............................. yes
    openh264 ............................. yes
Qt PDF:
Qt PDF:
   Support V8 ............................. no
   Support V8 ............................. no
Line 62: Line 104:
   Support XFA-PNG ........................ no
   Support XFA-PNG ........................ no
   Support XFA-TIFF ....................... no
   Support XFA-TIFF ....................... no
Qt PDF Widgets:
  Bitcode support ........................ no
   Support Qt PDF Widgets ................. yes
  Use static runtime ..................... no
SBOM:
   Generate SBOM .......................... yes
  Generate SPDX v2.3 ..................... yes
  Generate SPDX v2.3 JSON ................ yes (skipped if dependencies are missing)
  Verify  SPDX v2.3 JSON ................ yes (skipped if dependencies are missing)
  Generate CycloneDX v1.6 ................ no (skipped if dependencies are missing)
  Verify  CycloneDX v1.6 ................ yes (skipped if dependencies are missing)
  SBOM Python interpreter ................ Not found
  Generate source SPDX SBOM .............. no
Note:
Scanning for ide sources...
Please note configure can execute faster if called with:
'qt-configure-module path/to/src -- -DQT_SHOW_EXTRA_IDE_SOURCES=OFF'
WARNING: Qt WebEngine And Qt Pdf SBOM generation will be skipped due to missing dependencies. QT_INTERNAL_SBOM_PYTHON_EXECUTABLE is missing a valid path to a python interpreter
Required Python dependencies NOT found:  spdx_tools.spdx.clitools.pyspdxtools
</pre>


Note: QtWebEngine build is disabled by user.
*build
$ cmake --build . --parallel


Note: The following modules are not being compiled in this configuration:
==Building Qt and Qt PDF together==
    webenginecore
    webengine
    webenginewidgets


Qt is now configured for building. Just run 'make'.
When you build Qt you can include a build of Qt PDF.
Once everything is built, you must run 'make install'.
Qt will be installed into '/usr'.


$ make && make install
*get the qt5.git repository, submodules and dependencies as explained in [[Building Qt 6 from Git]]
</code>
*configure and build a shadow build:
<pre>
$ cd ..
$ mkdir qt6-dbg
$ cd qt6-dbg
$ ../qt6/configure -developer-build -debug -no-optimize-debug -nomake examples -make tests -no-pch -submodules qtbase,qtdeclarative,qtshadertools,qtwebengine -no-feature-qtwebengine-build
$ ninja
</pre>


First it builds tools if necessary (gn and ninja), then QtPDF. (If you don't give the -no-build-qtwebengine-core argument, it will spend a lot of time building QtWebEngine before building QtPDF.)
==Historical repository==


Examples are in examples/pdf and examples/pdfwidgets.
The older version in the [https://code.qt.io/cgit/qt-labs/qtpdf.git/ Qt Labs QtPDF repository] still exists, but development now continues in the [https://code.qt.io/cgit/qt/qtwebengine.git/tree/src/pdf qtwebengine repository].  This was prompted mainly by the upstream Chromium switch of build system from gyp to gn: it was some work to get qtwebengine building with that.  Chromium (and thus Qt WebEngine) includes PDFium already; so it was easier to build Qt PDF from there than to fix the build in the other repository.

Latest revision as of 14:05, 19 August 2026

Qt PDF binaries are available from the Qt installer under "Extensions"; but here's how to build it yourself.

In case of any issues, please open a bug report for the PDF component at Qt Bug Reports.

Building from git with an existing Qt 6

This step requires an existing Qt 6 installation.

  • Install html5lib: hopefully your system package manager provides a python3-html5lib package; alternatively:
$ pip3 install html5lib
  • Sources for the Qt PDF module are hosted within QtWebEngine repository. Clone and initialize the git repository (currently about 7.1 GB):

(Commercial Qt customers are advised to use their own access to the source code on git. See the page Getting Commercial Qt Sources for more details)

$ git clone https://code.qt.io/qt/qtwebengine.git
$ cd qtwebengine
$ git checkout 6.12 (or whatever version)
$ git submodule update --init --recursive
  • Fortunately build of QtWebEngine itself is not necessary for Qt PDF. Qt PDF uses just PDFium as a part of Chromium inside the QtWebEngine. Configure a shadow build:
$ mkdir build
$ cd build
$ <path to the "bin" folder in your Qt 6 installation>/qt-configure-module ../qtwebengine -- -DQT_FEATURE_qtwebengine_build=OFF
  • Build Qt PDF
$ cmake --build . --parallel
  • Install Qt PDF
$ cmake --install .

This will install Qt PDF into the Qt 6 installation you specified and used above.

Test the new build with one of the examples provided by Qt PDF. See folders examples/pdf and examples/pdfwidgets.

Building from source installed with the installer

In Qt Maintenance Tool (AKA the installer) you can choose Extensions | Qt PDF | Qt 6.xx.x | Desktop to get the already-built version, and/or Extensions | Qt WebEngine | Qt 6.xx.x | Sources to get the source code for Qt WebEngine and Qt PDF together.

  • configure a shadow build
$ cd ~/Qt/6.12.0/Src/qtwebengine (or whatever version)
$ mkdir build
$ cd build
$ <path to the "bin" folder of this Qt>/qt-configure-module .. -- -DQT_FEATURE_qtwebengine_build=OFF
...
 -- Configuration summary has been written to /home/username/Qt/6.12.0/Src/qtwebengine/build/config.summary
...
-- Configuring done (14.0s)
-- Generating done (0.1s)
-- Build files have been written to: /home/username/Qt/6.12.0/Src/qtwebengine/build

$ cat config.summary
WebEngine Repository Build Options:
  Build Gn ............................... yes
  Jumbo Build ............................ yes
  Developer build ........................ no
  Build with rust ........................ no
  Use precompiled headers for 3rdparty ... no
  Build QtWebEngine Modules:
    Build QtWebEngineCore ................ no
    Build QtWebEngineWidgets ............. no
    Build QtWebEngineQuick ............... no
  Build QtPdf Modules:
    Build QtPdfWidgets ................... yes
    Build QtPdfQuick ..................... yes
  Optional system libraries:
    re2 .................................. no
    icu .................................. no
    libwebp, libwebpmux and libwebpdemux . yes
    opus ................................. yes
    ffmpeg ............................... no
    libvpx ............................... no
    snappy ............................... yes
    glib ................................. yes
    zlib ................................. yes
    minizip .............................. yes
    libxml2 and libxslt .................. yes
    lcms2 ................................ yes
    png .................................. no
    tiff ................................. yes
    jpeg ................................. no
    libopenjpeg2 ......................... yes
    harfbuzz ............................. no
    freetype ............................. yes
    libpci ............................... yes
    libudev .............................. yes
    openh264 ............................. yes
Qt PDF:
  Support V8 ............................. no
  Support XFA ............................ no
  Support XFA-BMP ........................ no
  Support XFA-GIF ........................ no
  Support XFA-PNG ........................ no
  Support XFA-TIFF ....................... no
  Bitcode support ........................ no
  Use static runtime ..................... no
SBOM:
  Generate SBOM .......................... yes
  Generate SPDX v2.3 ..................... yes
  Generate SPDX v2.3 JSON ................ yes (skipped if dependencies are missing)
  Verify   SPDX v2.3 JSON ................ yes (skipped if dependencies are missing)
  Generate CycloneDX v1.6 ................ no (skipped if dependencies are missing)
  Verify   CycloneDX v1.6 ................ yes (skipped if dependencies are missing)
  SBOM Python interpreter ................ Not found
  Generate source SPDX SBOM .............. no
Note: 
Scanning for ide sources...
Please note configure can execute faster if called with:
 'qt-configure-module path/to/src -- -DQT_SHOW_EXTRA_IDE_SOURCES=OFF'
WARNING: Qt WebEngine And Qt Pdf SBOM generation will be skipped due to missing dependencies. QT_INTERNAL_SBOM_PYTHON_EXECUTABLE is missing a valid path to a python interpreter
Required Python dependencies NOT found:  spdx_tools.spdx.clitools.pyspdxtools
  • build
$ cmake --build . --parallel

Building Qt and Qt PDF together

When you build Qt you can include a build of Qt PDF.

  • get the qt5.git repository, submodules and dependencies as explained in Building Qt 6 from Git
  • configure and build a shadow build:
$ cd ..
$ mkdir qt6-dbg
$ cd qt6-dbg
$ ../qt6/configure -developer-build -debug -no-optimize-debug -nomake examples -make tests -no-pch -submodules qtbase,qtdeclarative,qtshadertools,qtwebengine -no-feature-qtwebengine-build
$ ninja

Historical repository

The older version in the Qt Labs QtPDF repository still exists, but development now continues in the qtwebengine repository. This was prompted mainly by the upstream Chromium switch of build system from gyp to gn: it was some work to get qtwebengine building with that. Chromium (and thus Qt WebEngine) includes PDFium already; so it was easier to build Qt PDF from there than to fix the build in the other repository.