Python 查看PDF';s

Python 查看PDF';s,python,interface,gtk,pygtk,glade,Python,Interface,Gtk,Pygtk,Glade,平台:Linux,GTK+ 工具:Python、PyGTK和Glade 问题: 我想写一个能够显示PDF文件的程序 问题: 我需要哪些小部件和Python模块 谢谢你的建议 不是GTK而是wxPython: 此示例显示了一个PDF查看器类,它处理缩放和滚动等操作。它需要python poppler和wxPython>=2.8.9 查看python poppler绑定 我以一种简单的肮脏方式呈现pdf文件。我复制了示例中用于python poppler gtk绑定的方法 def loa

平台:Linux,GTK+

工具:Python、PyGTK和Glade

问题:
  • 我想写一个能够显示PDF文件的程序
问题:
  • 我需要哪些小部件和Python模块
谢谢你的建议

不是GTK而是wxPython:

此示例显示了一个PDF查看器类,它处理缩放和滚动等操作。它需要python poppler和wxPython>=2.8.9


查看python poppler绑定

我以一种简单的肮脏方式呈现pdf文件。我复制了示例中用于python poppler gtk绑定的方法

def load_pdf(self):
    self.doc = poppler.document_new_from_file (uri, None)
    # the number of pages in the pdf
    self.n_pgs = self.document.get_n_pgs()
    # the current page of the pdf
    self.curr_pg = 0
    # the current page being displayed
    self.curr_pg_disp = self.document.get_page(self.curr_pg)
    # the scale of the page
    self.scale = 1
    # the document width and height
    self.doc_width, self.doc_height = self.curr_pg_disp.get_size()


def render_pdf(self):
    cr = self.pdfda.window.cairo_create()
    cr.set_source_rgb(1, 1, 1)
    if self.scale != 1:
        cr.scale(self.scale, self.scale)
    cr.rectangle(0, 0, self.doc_width, self.doc_height)
    cr.fill()
    self.curr_pg_disp.render(cr)

def on_next_btn_clicked(self, widget, data=None):
    if self.curr_pg < self.n_pgs:
        self.curr_pg = self.curr_pg + 1
        self.curr_pg_disp = self.doc.get_page(self.curr_pg)
        self.render_page()

def on_prev_btn_clicked(self, widget, data=None):
    if self.curr_pg > 0:
        self.curr_pg = self.curr_pg - 1
        self.curr_pg_disp = self.doc.get_page(self.curr_pg)
        self.render_page()
def load_pdf(self):
self.doc=poppler.document\u新\u来自\u文件(uri,无)
#pdf中的页数
self.n_pgs=self.document.get_n_pgs()
#pdf的当前页面
self.curr\u pg=0
#正在显示的当前页面
self.curr\u pg\u disp=self.document.get\u页面(self.curr\u pg)
#页面的比例
self.scale=1
#文档的宽度和高度
self.doc\u width,self.doc\u height=self.curr\u pg\u disp.get\u size()
def render_pdf(self):
cr=self.pdfda.window.cairo\u create()
cr.set_源_rgb(1,1,1)
如果是自缩放!=1:
cr刻度(自刻度,自刻度)
cr矩形(0,0,self.doc\u宽度,self.doc\u高度)
cr.fill()
自电流pg显示渲染(cr)
单击下一个按钮时的def(自我、小部件、数据=无):
如果self.curr\u pg0:
self.curr\u pg=self.curr\u pg-1
self.curr\u pg\u disp=self.doc.get\u页面(self.curr\u pg)
self.render_页面()
它不是最好或最漂亮的,但它很有效。我仍然需要添加如何使其在绘图区域中滚动或居中,以及类似的内容,但这是一个开始


您还可以查看evincepython绑定,我相信它们有一个小部件,您可以使用它来简化pdf呈现。我是在windows上开发的,所以如果有,我就没用过

你想在这里干什么?在屏幕上显示它,或者将其转换为其他内容来显示它?只需在屏幕上显示它,而无需启动现有的pdf查看器。我不认为如果链接过时,谷歌搜索“python ghostscript”超出任何人的能力。你有使用python查看pdf文件的完整代码吗?介意分享吗?