Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to preview pdfs in a PyQt application?

I'm working on a file manager in Python for windows using PyQt4 that deals almost exclusively with pdfs. I'd like to keep it portable so I can run it off a usb stick.

Is it possible to preview a pdf, similar to this

http://www.neosoftware.com/neobook/modules/pubs/singlefile.php?cid=8&lid=68

but using python and pyqt?

like image 523
Insarov Avatar asked Aug 02 '13 19:08

Insarov


1 Answers

Sure, soultion is here(python-poppler-qt4 is a Python binding to the Poppler PDF library):

  • https://code.google.com/p/python-poppler-qt4/

Sample of use:

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_())
like image 136
adamr Avatar answered Oct 10 '22 14:10

adamr