Poppler Qt5 24.11.0
The Poppler Qt5 interface library

The Poppler Qt5 interface library, libpoppler-qt5, is a library that allows Qt5 programmers to easily load and render PDF files. The Poppler Qt5 interface library uses poppler internally to do its job, but the Qt5 programmer will never have to worry about poppler internals.

Current Status

The Poppler Qt5 interface library is quite stable and working.

Example Programs

Examples programs can be found in the qt5/test directory. The Poppler Qt5 interface library is also used in the KDE's document viewer Okular. The source files for Okular's PDF plugin (Poppler-based) can be found on the git server of the KDE project, under this URL.

How to use the Poppler Qt5 interface library in three easy steps

Programmer who would like to use the Poppler Qt5 interface library simply need to add the following line to their C++ source files:

#include <poppler-qt5.h>

To use the Qt5 interface on Android, there is an additional step - you must place the following font files in the assets/share/fonts directory of the Android APK:

  • NimbusMonoPS-Regular.otf
  • NimbusMonoPS-Bold.otf
  • NimbusMonoPS-BoldItalic.otf
  • NimbusMonoPS-Italic.otf
  • NimbusSans-Regular.otf
  • NimbusSans-Bold.otf
  • NimbusSans-BoldItalic.otf
  • NimbusSans-Italic.otf
  • StandardSymbolsPS.otf
  • NimbusRoman-Bold.otf
  • imbusRoman-BoldItalic.otf
  • NimbusRoman-Italic.otf
  • NimbusRoman-Regular.otf
  • D050000L.otf

These are used as substitute fonts for the base-14 fonts, and this step is required in order to reliably display documents with unembedded fonts. You can easily find these font files included within GhostScript.

A PDF document can then be loaded as follows:

QString filename;
if (!document || document->isLocked()) {
// ... error message ....
delete document;
return;
}
PDF document.
Definition poppler-qt5.h:1146
static Document * load(const QString &filePath, const QByteArray &ownerPassword=QByteArray(), const QByteArray &userPassword=QByteArray())
Load the document from a file on disk.
bool isLocked() const
Determine if the document is locked.

Pages can be rendered to QImages with the following commands:

// Paranoid safety check
if (document == 0) {
// ... error message ...
return;
}
// Access page of the PDF file
Poppler::Page* pdfPage = document->page(pageNumber); // Document starts at page 0
if (pdfPage == 0) {
// ... error message ...
return;
}
// Generate a QImage of the rendered page
QImage image = pdfPage->renderToImage(xres, yres, x, y, width, height);
if (image.isNull()) {
// ... error message ...
return;
}
// ... use image ...
// after the usage, the page must be deleted
delete pdfPage;
Page * page(int index) const
Get a specified Page.
A page in a document.
Definition poppler-qt5.h:436
QImage renderToImage(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1, Rotation rotate=Rotate0) const
Render the page to a QImage using the current Document renderer.

Finally, don't forget to destroy the document:

delete document;