嵌入了evince Python GI

时间:2012-01-20 14:07:27

标签: python pdf gtk

我想通过使用gi存储库将其嵌入Python来查看pdf文档。我正在尝试使用

代码here
#!/usr/bin/env python

from gi.repository import Gtk, Gio
from gi.repository import EvinceDocument
from gi.repository import EvinceView

class HelloWorldApp(Gtk.Application):
   def __init__(self):
       Gtk.Application.__init__(self, application_id="apps.test.helloevince", flags=Gio.ApplicationFlags.FLAGS_NONE)
       self.connect("activate", self.on_activate)

   def on_activate(self, data=None):
       window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
       window.set_title("Evince Gtk3 Python Example")
       window.set_border_width(24)
       scroll = Gtk.ScrolledWindow()
       window.add(scroll)
       EvinceDocument.init()
       doc = EvinceDocument.Document.factory_get_document('file:///home/user/test.pdf')
       view = EvinceView.View()
       model = EvinceView.DocumentModel()
       model.set_document(doc)
       view.set_model(model)
       scroll.add(view)
       window.show_all()
       self.add_window(window)

if __name__ == "__main__":
   app = HelloWorldApp()
   app.run(None)

但是我收到了错误

Traceback (most recent call last):
  File "./pdfViewer_pygi.py", line 19, in on_activate
    doc = EvinceDocument.Document.factory_get_document('file:///home/user/test.pdf')
AttributeError: type object 'Document' has no attribute 'factory_get_document'

很明显,没有'factory_get_document'方法。那么替代方案是什么......?如何使用python和gtk + 3嵌入pdf文档??

1 个答案:

答案 0 :(得分:2)

您需要更新版本的Evince。

这对我来说最新的Evince,3.3.3.1,使用Fedora 17(rawhide),并且在使用Fedora 16的Evince 3.2.1中不起作用。

也许你可以编译Evince以使绑定工作。