1#include <QtCore/QDebug>
2#include <QtCore/QDir>
3#include <QtCore/QElapsedTimer>
4#include <QtWidgets/QApplication>
5#include <QtGui/QImage>
6
7#include <iostream>
8
9#include <poppler-qt6.h>
10
11int main(int argc, char **argv)
12{
13 QApplication a(argc, argv); // QApplication required!
14
15 QElapsedTimer t;
16 t.start();
17
18 QDir directory(argv[1]);
19 foreach (const QString &fileName, directory.entryList()) {
20 if (fileName.endsWith(QStringLiteral("pdf"))) {
21 qDebug() << "Doing" << fileName.toLatin1().data() << ":";
22 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: directory.canonicalPath() + "/" + fileName);
23 if (!doc) {
24 qWarning() << "doc not loaded";
25 } else if (doc->isLocked()) {
26 if (!doc->unlock(ownerPassword: "", userPassword: "password")) {
27 qWarning() << "couldn't unlock document";
28 }
29 } else {
30 auto pdfVersion = doc->getPdfVersion();
31 Q_UNUSED(pdfVersion);
32 doc->info(QStringLiteral("Title"));
33 doc->info(QStringLiteral("Subject"));
34 doc->info(QStringLiteral("Author"));
35 doc->info(QStringLiteral("Keywords"));
36 doc->info(QStringLiteral("Creator"));
37 doc->info(QStringLiteral("Producer"));
38 doc->date(QStringLiteral("CreationDate")).toString();
39 doc->date(QStringLiteral("ModDate")).toString();
40 doc->numPages();
41 doc->isLinearized();
42 doc->isEncrypted();
43 doc->okToPrint();
44 doc->okToCopy();
45 doc->okToChange();
46 doc->okToAddNotes();
47 doc->pageMode();
48
49 for (int index = 0; index < doc->numPages(); ++index) {
50 std::unique_ptr<Poppler::Page> page = doc->page(index);
51 page->renderToImage();
52 page->pageSize();
53 page->orientation();
54 std::cout << ".";
55 std::cout.flush();
56 }
57 std::cout << std::endl;
58 }
59 }
60 }
61
62 std::cout << "Elapsed time: " << (t.elapsed() / 1000) << "seconds" << std::endl;
63}
64

source code of poppler/qt6/tests/stress-poppler-dir.cpp