1#include <QtCore/QCoreApplication>
2#include <QtCore/QDebug>
3
4#include <iostream>
5#include <memory>
6
7#include <poppler-qt6.h>
8
9int main(int argc, char **argv)
10{
11 QCoreApplication a(argc, argv); // QApplication required!
12
13 if (!(argc == 2)) {
14 qWarning() << "usage: poppler-page-labels filename";
15 exit(status: 1);
16 }
17
18 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: argv[1]);
19 if (!doc || doc->isLocked()) {
20 qWarning() << "doc not loaded";
21 exit(status: 1);
22 }
23
24 for (int i = 0; i < doc->numPages(); i++) {
25 int j = 0;
26 std::cout << "*** Label of Page " << i << std::endl;
27 std::cout << std::flush;
28
29 std::unique_ptr<Poppler::Page> page(doc->page(index: i));
30
31 if (!page) {
32 continue;
33 }
34
35 const QByteArray utf8str = page->label().toUtf8();
36 for (j = 0; j < utf8str.size(); j++) {
37 std::cout << utf8str[j];
38 }
39 std::cout << std::endl;
40
41 std::unique_ptr<Poppler::Page> pageFromPageLabel(doc->page(label: page->label()));
42 const int indexFromPageLabel = pageFromPageLabel ? pageFromPageLabel->index() : -1;
43 if (indexFromPageLabel != i) {
44 std::cout << "WARNING: Page label didn't link back to the same page index " << indexFromPageLabel << " " << i << std::endl;
45 }
46 }
47}
48

source code of poppler/qt6/tests/poppler-page-labels.cpp