打开PDF以添加书签/命名目的地? [英] Open PDF to Bookmark/Named Destination?
问题描述
我正在尝试使用python打开指向特定书签的PDF.
I'm trying to open a PDF to a specific bookmark using python.
到目前为止,我已经能够在命令提示符中运行以下命令,并得到我想要的内容( last 是PDF test.pdf中指定目标的名称)
So far, I'm able to run the following command in Command Prompt and get exactly what I want (last is the name of a named destination inside the PDF test.pdf)
"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /A "nameddest=last" "C:\Users\User\Desktop\test.pdf"
但是当我使用Python并尝试使用子过程模块时,就像这样:
But when I go to Python and try using the subprocess module like this:
import subprocess
subprocess.call(['"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /A "nameddest=last" "C:\\Users\\User\Desktop\test.pdf"'], shell=True)
我得到文件名,目录名或卷标签语法不正确."在尝试此操作之前,我尝试过一些操作,导致Adobe Reader打开,但是给我一个对话框,显示相同的消息
I get "The filename, directory name, or volume label syntax is incorrect." Something I tried before this caused Adobe Reader to open, but give me a dialog box that had the same message
为什么在python中运行它会发生什么变化?以及我该如何解决?
我正在Windows 8上运行Anaconda 2.1.0,并使用Acrobat 10创建目标.我已经在python上玩了2-3年,但对知识的了解并不比在入门编程班上学一个学期的人多.
I'm running Anaconda 2.1.0 on Windows 8 and using Acrobat 10 to create Destinations. I've played around with python for 2-3 years, but don't know much more than someone with 1 semester of an intro programming class.
推荐答案
已修复:
我是个白痴.
FIXED:
I'm an idiot.
"C:\\Users\\User\Desktop\test.pdf"
是无效的路径,因为\ test.pdf中的\ t被解释为制表符... 将更改添加到\ test.pdf后,它可以工作.
is an invalid path because the \t in \test.pdf is interpretted as a tab... It works after adding changing it to \test.pdf.
以后有相同问题的任何人的代码:
Code for anyone with the same problem later:
import os
import subprocess
page = "3"
path_to_pdf = os.path.abspath("C:\\Users\\User\Desktop\\test.pdf")
path_to_acrobat = os.path.abspath('C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe')
process = subprocess.Popen([path_to_acrobat, '/n', '/A', 'page=' + page, path_to_pdf], shell=False, stdout=subprocess.PIPE)
process.wait()
这篇关于打开PDF以添加书签/命名目的地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!