Archie3d / qpdf

PDF viewer widget for Qt
GNU Lesser General Public License v2.1
170 stars 57 forks source link
pdf pdf-viewer pdf-viewer-widget qt5

QPdf

PDF viewer widget for Qt 5.

This is a wrapper of pdf.js JavaScript PDF renderer using Qt WebEngine.

Screenshot

This qmake-based project defines two build targets: qpdf shared library, and an example PDF viewer (pdfviewer) based on qpdf library. Should yoo want to integrate a PDF view into your project, you need to take qpdf library only, you do not need pdfviewer (though you may use it as inspirational example for your project). So you may copy qpdflib into your project and build it as a shared library to be linked with your code.

How to compile

Open PDF files

qpdf library offers two ways to open PDF files:

loadData method serializes PDF data as base64 string and injects it into JavaScript environment. This may fails however when loading huge PDF files.

loadFile can load PDFs of any size, however the method is blocked by default due to the cross-origin security restriction, since it uses WebEngine's load URL method. In order to make this method work, you have to disable web security by passing --disable-web-security argument to your QApplication instance (see how its done in pdfviwer example).

Debugging

If something goes wrong, as sometimes it does, you may use Chromium debug console to assess the situation:

Qt Quick Compiler Issue

This project includes JavaScript *.js files as resources. Qt Creator may try to add them to QML resources instead, which makes the web engine unable to load *.js from normal resources. This happens on Windows in Release builds automatically (but not in Debug for some reason). Make sure to disable Qt Quick Compiler in your project build settings: Disable Qt Quick