[英]Python - open pdf file to specific page/section
是否可以從 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()
至於部分,你可以看看這個答案
從這個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
其中wordlist
是由空格分隔的單詞列表。 將打開文檔並執行搜索,第一個結果將突出顯示。 這樣,作為wordlist
,你可以嘗試把部分的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.