1#include <QtCore/QCoreApplication>
2#include <QtCore/QDebug>
3
4#include <iostream>
5
6#include <poppler-qt6.h>
7
8int main(int argc, char **argv)
9{
10 QCoreApplication a(argc, argv); // QApplication required!
11
12 if (!(argc == 2)) {
13 qWarning() << "usage: poppler-texts filename";
14 exit(status: 1);
15 }
16
17 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: argv[1]);
18 if (!doc) {
19 qWarning() << "doc not loaded";
20 exit(status: 1);
21 }
22
23 for (int i = 0; i < doc->numPages(); i++) {
24 int j = 0;
25 std::cout << "*** Page " << i << std::endl;
26 std::cout << std::flush;
27
28 std::unique_ptr<Poppler::Page> page = doc->page(index: i);
29 const QByteArray utf8str = page->text(rect: QRectF(), textLayout: Poppler::Page::RawOrderLayout).toUtf8();
30 std::cout << std::flush;
31 for (j = 0; j < utf8str.size(); j++) {
32 std::cout << utf8str[j];
33 }
34 std::cout << std::endl;
35 }
36}
37

source code of poppler/qt6/tests/poppler-texts.cpp