3
votes

I am using windows 10 and python 2.7.13 . My target is to open a pdf in acrobat reader at a specific page number. I am using the code I received from one of the questions in the forum here.

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()

It opens up the acrobat reader application but the file doesnt open and i get the error :"There was an error opening this document. The filename, directory name, or volume label syntax is incorrect

but when I use these commands in cmd without python I am successfully able to open the pdf without any error. Please help.

2

2 Answers

3
votes

Try to open the file with r:

path_to_pdf = os.path.abspath(r'C:\test_file.pdf')
path_to_acrobat = os.path.abspath(r'C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe') 

Check this out too, it will show to you an example of an error with the white spaces on the path

1
votes

Please check the path of your acrobat reader. In my case:

path_to_acrobat = os.path.abspath('C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\AcroRd32.exe')