I have grabbed a pdf from the web using for example
import requests
pdf = requests.get("http://www.scala-lang.org/docu/files/ScalaByExample.pdf")
I would like to modify this code to display it
from gi.repository import Poppler, Gtk
def draw(widget, surface):
page.render(surface)
document = Poppler.Document.new_from_file("file:///home/me/some.pdf", None)
page = document.get_page(0)
window = Gtk.Window(title="Hello World")
window.connect("delete-event", Gtk.main_quit)
window.connect("draw", draw)
window.set_app_paintable(True)
window.show_all()
Gtk.main()
How do I modify the document =
line to use the variable pdf that contains the pdf?
(I don't mind using popplerqt4 or anything else if that makes it easier.)
Poppler.Document.new_from_data
, however there is a conversion problem betweenstr
andchar *
due to the waystr
is expected to carry Unicode data, butchar *
expects raw binary data. Up to now, I couldn't make it work. – Corronlen(repr(content))
for length field andstr(content)
for the data field. It worked for me. – Warfold