summaryrefslogtreecommitdiff
path: root/qt4/tests/poppler-texts.cpp
blob: ec28353156ef31b2c050ab946683e91b111c06f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>

#include <iostream>

#include <poppler-qt4.h>

int main( int argc, char **argv )
{
    QCoreApplication a( argc, argv );               // QApplication required!

    if (!( argc == 2 ))
    {
	qWarning() << "usage: poppler-texts filename";
	exit(1);
    }
  
    Poppler::Document *doc = Poppler::Document::load(argv[1]);
    if (!doc)
    {
	qWarning() << "doc not loaded";
	exit(1);
    }

    for ( int i = 0; i < doc->numPages(); i++ )
    {
      int j = 0;
      std::cout << "*** Page " << i << std::endl;
      std::cout << std::flush;

      Poppler::Page *page = doc->page(i);
      const QByteArray utf8str = page->text( QRectF(), Poppler::Page::RawOrderLayout ).toUtf8();
      std::cout << std::flush;
      for ( j = 0; j < utf8str.size(); j++ )
        std::cout << utf8str[j];
      std::cout << std::endl;
      delete page;
    }
    delete doc;
}