Debian Codegraph @

qt5/tests/stress-poppler-dir.cpp

raw
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-qt5.h>
10
11 int main(int argc, char **argv)
12 {
13 QApplication a(argc, argv); // QApplication required!
14
15 QElapsedTimer t;
16 t.start();
17
18 QDir directory(QString::fromLocal8Bit(argv[1]));
19 Q_FOREACH (const QString &fileName, directory.entryList()) {
20 if (fileName.endsWith(QStringLiteral("pdf"))) {
21 qDebug() << "Doing" << fileName.toLatin1().data() << ":";
22 Poppler::Document *doc = Poppler::Document::load(directory.canonicalPath() + QChar::fromLatin1('/') + fileName);
23 if (!doc) {
24 qWarning() << "doc not loaded";
25 } else if (doc->isLocked()) {
26 if (!doc->unlock("", "password")) {
27 qWarning() << "couldn't unlock document";
28 delete doc;
29 }
30 } else {
31 auto pdfVersion = doc->getPdfVersion();
32 if (pdfVersion.major != 1) {
33 qWarning() << "pdf major version is not '1'";
34 }
35
36 doc->info(QStringLiteral("Title"));
37 doc->info(QStringLiteral("Subject"));
38 doc->info(QStringLiteral("Author"));
39 doc->info(QStringLiteral("Keywords"));
40 doc->info(QStringLiteral("Creator"));
41 doc->info(QStringLiteral("Producer"));
42 doc->date(QStringLiteral("CreationDate")).toString();
43 doc->date(QStringLiteral("ModDate")).toString();
44 doc->numPages();
45 doc->isLinearized();
46 doc->isEncrypted();
47 doc->okToPrint();
48 doc->okToCopy();
49 doc->okToChange();
50 doc->okToAddNotes();
51 doc->pageMode();
52
53 for (int index = 0; index < doc->numPages(); ++index) {
54 Poppler::Page *page = doc->page(index);
55 page->renderToImage();
56 page->pageSize();
57 page->orientation();
58 delete page;
59 std::cout << ".";
60 std::cout.flush();
61 }
62 std::cout << std::endl;
63 delete doc;
64 }
65 }
66 }
67
68 std::cout << "Elapsed time: " << (t.elapsed() / 1000) << "seconds" << std::endl;
69 }