Pdf + “Cute” [Touchulator]

Posted: February 3, 2013 in Work
Tags: , ,

So finally i have started my work on “something” new. Lets see how far this goes. So at first I was trying to read pdf file using QT. I found that QT itself does not come with any support to read pdf. However, there are many APIs available for QT. One of them being “Poppler”. Poppler (or libpoppler) is a free software library used to render PDF documents. Hence, I tried to implement poppler with QT.

If we skip the initial googling time, the task was not too difficult. All I had to do was to build poppler library. And then read pdf using this popeller library and rander pages as images. Now this image could easily be displayed thorugh QT.


Screenshot from 2013-02-03 13:34:41




For very basic implementation , this is the code:

QString filename = “/media/BACC8094CC804C97/Docs/Work Docs/PDF/IP/OReilly Learning OpenCV.pdf”;

Poppler::Document* document = Poppler::Document::load(filename);
if (!document || document->isLocked())
// … error message ….
delete document;
// Paranoid safety check
if (document == 0) {
// … error message …
// Access page of the PDF file
int pageNumber = 1;
Poppler::Page* pdfPage = document->page(pageNumber); // Document starts at page 0
if (pdfPage == 0) {
// … error message …
// Generate a QImage of the rendered page
double xres=150.0,yres=200.0;

image = pdfPage->renderToImage(xres, yres, 0, 0, 1000, 1000);
if (image.isNull()) {
// … error message …
// … use image …
// after the usage, the page must be deleted
delete pdfPage;
delete document;



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s