Python error cannot open pdf in application from python
I am using windows 10 and python 2.7.13. My goal is to open the pdf file in acrobat reader at a specific page number. I am using the code I got from one of the questions on 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 the acrobat reader application, but the file does not open, and I get the error: "Error opening this document. Invalid file name, directory name or volume label syntax
but when i use these commands in cmd without python i can successfully open pdf without error. Please, help.
+3
source to share
2 answers
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 too , it will show you an example of an error with spaces in the path
+3
source to share