1 // Copyright 2011 The Emscripten Authors.  All rights reserved.
2 // Emscripten is available under two separate licenses, the MIT license and the
3 // University of Illinois/NCSA Open Source License.  Both these licenses can be
4 // found in the LICENSE file.
5 
6 #include <QtCore/QDebug>
7 #include <QtCore/QDir>
8 #include <QtCore/QTime>
9 #include <QtGui/QApplication>
10 #include <QtGui/QImage>
11 
12 #include <iostream>
13 
14 #include <poppler-qt4.h>
15 
main(int argc,char ** argv)16 int main( int argc, char **argv )
17 {
18     QApplication a( argc, argv );               // QApplication required!
19 
20     Q_UNUSED( argc );
21     Q_UNUSED( argv );
22 
23     QTime t;
24     t.start();
25     QDir dbDir( QString( "./pdfdb" ) );
26     if ( !dbDir.exists() ) {
27 	qWarning() << "Database directory does not exist";
28     }
29 
30     QStringList excludeSubDirs;
31     excludeSubDirs << "000048" << "000607";
32 
33     foreach ( const QString &subdir, dbDir.entryList(QStringList() << "0000*", QDir::Dirs) ) {
34 	if ( excludeSubDirs.contains(subdir) ) {
35 	    // then skip it
36 	} else {
37 	    QString path = "./pdfdb/" + subdir + "/data.pdf";
38 	    std::cout <<"Doing " << path.toLatin1().data() << " :";
39 	    Poppler::Document *doc = Poppler::Document::load( path );
40 	    if (!doc) {
41 		qWarning() << "doc not loaded";
42 	    } else {
43 		int major = 0, minor = 0;
44 		doc->getPdfVersion( &major, &minor );
45 		doc->info("Title");
46 		doc->info("Subject");
47 		doc->info("Author");
48 		doc->info("Keywords");
49 		doc->info("Creator");
50 		doc->info("Producer");
51 		doc->date("CreationDate").toString();
52 		doc->date("ModDate").toString();
53 		doc->numPages();
54 		doc->isLinearized();
55 		doc->isEncrypted();
56 		doc->okToPrint();
57 		doc->okToCopy();
58 		doc->okToChange();
59 		doc->okToAddNotes();
60 		doc->pageMode();
61 
62 		for( int index = 0; index < doc->numPages(); ++index ) {
63 		    Poppler::Page *page = doc->page( index );
64 		    QImage image = page->renderToImage();
65 		    page->pageSize();
66 		    page->orientation();
67 		    delete page;
68 		    std::cout << ".";
69 		    std::cout.flush();
70 		}
71 		std::cout << std::endl;
72 		delete doc;
73 	    }
74 	}
75     }
76 
77     std::cout << "Elapsed time: " << (t.elapsed()/1000) << std::endl;
78 
79 }
80