是否有可能从Python中打开PDF,使其跳转到特定的页面或部分?我的想法是打开一个帮助文件(PDF),并跳转到请求帮助的部分。
是否有可能从Python中打开PDF,使其跳转到特定的页面或部分?我的想法是打开一个帮助文件(PDF),并跳转到请求帮助的部分。
以下是两个基本思路
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()
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
,其中wordlist
是由空格分隔的单词列表。文档将被打开并执行搜索,第一个结果将被突出显示。作为wordlist
,您可以尝试放置章节名称。
print(pageObj.extractText())
为什么会返回 None 或 ''? - Manuel Carrero