2016-05-07 12 views
2

Ich mache ein Programm, wo ein Teil davon ein PDF-Dokument in Chrom zu öffnen. Das Programm wird in Python 3.5.x gemacht. Das Programm gibt bei der Ausführung keine Fehler zurück, es werden jedoch keine neuen Registerkarten oder Fenster geöffnet. mit dem .pdf. Ich benutze das Webbrowser-Modul.Öffnen eines PDF-Dokuments in Chrom mit Python

chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s' 
    webbrowser.get(chrome_path).open_new('http://google.com') 
    #'file:///I:/TESTFOLDER/SDDsyllabus.pdf' 

Antwort

2

können Sie Subprocess, das zu tun verwenden:

import subprocess 
chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe #Notice how I'm using the backslash '\' not the normals slash '/'/ 
p = subprocess.Popen([chrome_path, "!%!PUT PATH TO PDF FILE HERE!%!"]) #This uses 'Subprocess' to open the file 
returncode = p.wait() #This waits for the process to close 

Was sie tut, ist offen eine Datei mit einem Prozess, öffnet es im Grunde, dass Datei mit (in diesem Fall) Chrome.

Hinweis: Dies öffnet ein neues Fenster und keine neue Registerkarte.

hoffe, das hilft :-)

Wenn Sie weitere Hilfe benötigen, fragen Sie einfach.

~ Coolq

+0

dank Mann, wirkt wie ein Zauber. – furthoc

+0

Kein Problem Mann :) –

Verwandte Themen