特定のページまたはセクションに移動するように、Python 内から PDF を開くことは可能ですか? 私が考えているのは、ヘルプ ファイル (pdf) を開いて、ヘルプが要求されているセクションにジャンプさせることです。
14110 次
1 に答える
8
ここに2つの基本的な考え方があります
ケース 1: ファイルを Python で開きたい場合
from pyPdf import PdfFileReader, PageObject
pdf_toread = PdfFileReader(path_to_your_pdf)
# 1 is the number of the page
page_one = pdf_toread.getPage(1)
# This will dump the content (unicode string)
# According to the doc, the formatting is dependent on the
# structure of the document
print page_one.extractText()
セクションについては、この回答を見ることができます
ケース 2: 特定のページでファイルを開くために acrobat を呼び出す場合
このAcrobat ヘルプ ドキュメントから、これをサブプロセスに渡すことができます。
import subprocess
import os
path_to_pdf = os.path.abspath('C:\test_file.pdf')
# I am testing this on my Windows Install machine
path_to_acrobat = os.path.abspath('C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe')
# this will open your document on page 12
process = subprocess.Popen([path_to_acrobat, '/A', 'page=12', path_to_pdf], shell=False, stdout=subprocess.PIPE)
process.wait()
単なる提案: 特定のセクションでファイルを開きたい場合は、スペースで区切られた単語のリストであるパラメータsearch=wordList
whereを使用できます。wordlist
ドキュメントが開かれ、検索が実行され、最初の結果が強調表示されます。このようにwordlist
、セクションの名前を入れてみることができます。
于 2012-04-04T16:11:24.873 に答える