Created
October 15, 2009 17:17
-
-
Save Ramblurr/211116 to your computer and use it in GitHub Desktop.
Qt4 Poppler bindings to convert a pdf file into text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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