Skip to content

Instantly share code, notes, and snippets.

@Ramblurr
Created October 15, 2009 17:17
Show Gist options
  • Save Ramblurr/211116 to your computer and use it in GitHub Desktop.
Save Ramblurr/211116 to your computer and use it in GitHub Desktop.
Qt4 Poppler bindings to convert a pdf file into text
#include <poppler-qt4.h>
#include <QRectF>
#include <QDebug>
#include <QFile>
#include <QTextStream>
void pdftotext( const QString &filename )
{
Poppler::Document *doc = Poppler::Document::load(filename);
int count = doc->numPages();
QFile outfile(filename+".txt");
if ( !outfile.open( QIODevice::WriteOnly ) )
{
qDebug() << "file open failed";
return;
}
QTextStream out(&outfile);
for(int i = 0; i < count; i ++)
{
QString text = doc->page(i)->text(QRectF());
out << text;
}
outfile.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment