Rendering PDF files in PyQt4 with pypoppler-qt4

Check out the new site at https://rkblog.dev.

Poppler is a library for rendering PDF files used by GTK+ and Qt applications. There is a widget for PyQt4 and PyGTK. To compile those widgets you need poppler-bindings package with Qt4 and/or GTK support. Snapshot of pypoppler-qt4 is available on pyqt4-extrawidgets. To compile the widget execute python configure.py, make, make install.

In the package you will find test-poppler.py, which will open a PDF file given as the argument for the file. You can use up/down arrows to change pages.

pypoppler

In this case Poppler will generate images and QPainter will be used to paint them. As we have images then we can use PictureFlow also:
import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import QtPoppler
from pictureflow import *

app = QApplication(sys.argv)

w = PictureFlow()
d = QtPoppler.Poppler.Document.load('file.pdf')
d.setRenderHint(QtPoppler.Poppler.Document.Antialiasing and QtPoppler.Poppler.Document.TextAntialiasing)

page = 0
pages = d.numPages() - 1
while page < pages:
	page += 1
	print page
	w.addSlide(d.page(page).renderToImage())
w.show()

sys.exit(app.exec_())
pypoppler1
RkBlog

PyQt and GUI, 2 January 2009


Check out the new site at https://rkblog.dev.
Comment article
Comment article RkBlog main page Search RSS Contact