[poppler] poppler.document_new_from_data usage

Carl Karsten cfkarsten at gmail.com
Fri Dec 26 21:52:40 PST 2008


I am trying to convert pdf to image in python to make thumbnails of a pdf that
can be displayed on a web page.  I think the poppler python bindings
will do it,
but I am pretty sure I am missing something.

Given this failed attempt, can someone strighten it out?

#!/usr/bin/python
# p2i.py
# test of converting a pdf to an image.

import poppler
import gtk

# there isn't really a pdf file on disk.
# pdf comes from mkpdf(), but this makes it easier to test.
pdf=open('foo.pdf','rb').read()

# I do this to avoid
# TypeError: document_new_from_data() argument 1 must be string without null
bytes, not str
# which is probably an indication I am already lost.
pdf=(pdf.replace('\x00','a')

p = poppler.document_new_from_data(pdf,len(pdf),'')
p0=p.get_page(0)

pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,300,300)

pb=p0.render_to_pixbuf(0,0,8,11,1,0,pixbuf)

# Error (40155): Unknown operator 'e'


Carl K


More information about the poppler mailing list