1
#include <qapplication.h>
6
#include <qmessagebox.h>
9
#include <poppler-qt.h>
12
class PDFDisplay : public QWidget // picture display widget
15
PDFDisplay( Poppler::Document *d );
18
void paintEvent( QPaintEvent * );
19
void keyPressEvent( QKeyEvent * );
25
Poppler::Document *doc;
28
PDFDisplay::PDFDisplay( Poppler::Document *d )
36
PDFDisplay::~PDFDisplay()
42
void PDFDisplay::paintEvent( QPaintEvent *e )
44
QPainter paint( this ); // paint widget
46
paint.drawPixmap(0, 0, *pixmap);
49
void PDFDisplay::keyPressEvent( QKeyEvent *e )
51
if (e->key() == Qt::Key_Down)
53
if (currentPage + 1 < doc->getNumPages())
59
else if (e->key() == Qt::Key_Up)
69
void PDFDisplay::display()
72
Poppler::Page *page = doc->getPage(currentPage);
75
page->renderToPixmap(&pixmap, -1, -1, -1, -1);
80
printf("doc not loaded\n");
84
int main( int argc, char **argv )
86
QApplication a( argc, argv ); // QApplication required!
88
if ( argc < 2 || (argc == 3 && strcmp(argv[2], "-extract") != 0) || argc > 3)
90
// use argument as file name
91
printf("usage: test-poppler-qt filename [-extract]\n");
95
Poppler::Document *doc = Poppler::Document::load(argv[1]);
98
printf("doc not loaded\n");
104
PDFDisplay test( doc ); // create picture display
105
a.setMainWidget( &test); // set main widget
106
test.setCaption("Poppler-Qt Test");
107
test.show(); // show it
109
return a.exec(); // start event loop
113
Poppler::Page *page = doc->getPage(0);
115
QLabel *l = new QLabel(page->getText(Poppler::Rectangle()), 0);
117
a.setMainWidget(l); // set main widget