问题
I'm trying to open a PDF to a specific bookmark using python.
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"
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)
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
Why does what happens changes when I run it in python? And how can I fix it?
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.
回答1:
FIXED:
I'm an idiot.
"C:\\Users\\User\Desktop\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()
来源:https://stackoverflow.com/questions/30288797/open-pdf-to-bookmark-named-destination