Opening pdf file

Question:

I wanna open pdf file from python console, I can do it with os.system(filename), it will open in adobe reader, but the problem is that os.system also opens a command prompt, is there another way that won’t open command prompt?

Asked By: Aleksa

||

Answers:

Try:

import subprocess
subprocess.Popen([file],shell=True)
Answered By: Daniel Wärnå
import webbrowser
webbrowser.open_new(r'file://C:pathtofile.pdf')
Answered By: Static Void

This is a bit late but nobody mentioned:

open("file_name.pdf")
Answered By: Astrophe
import os
os.startfile(filename)
Answered By: Raj Stha
open("file_name.pdf")

This code is giving the following error for me.

(unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated UXXXXXXXX escape

Answered By: Dev Mallik
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.