プラットフォーム: Linux、GTK +
ツール: Python、PyGTK、Glade。
問題:
- PDFファイルを表示できるプログラムを書きたいのですが。
質問:
- どのウィジェットとPythonモジュールが必要ですか?
提案をありがとう!
PythonPopplerバインディングを調べます。
私は単純な汚い方法でPDFファイルをレンダリングします。pythonpopplergtkバインディングの例で使用されているメソッドをコピーしました
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()
それは最高でもきれいでもありませんが、それは機能します。スクロール可能にする方法や描画領域の中央に配置する方法などを追加する必要がありますが、開始点があります。
evince pythonバインディングを調べることもできますが、PDFレンダリングを簡単にするために使用できるウィジェットがあると思います。私はWindowsで開発しているので、もしあればそれを使用していません。
GTKではなくwxPython:
この例は、ズームやスクロールなどを処理するPDFビューアクラスを示しています。python-popplerとwxPython>=2.8.9が必要です。