@@ -18,16 +18,21 @@ def open_application(app_name):
18
18
19
19
def preview_pdf (file_path ):
20
20
"""Preview a PDF file."""
21
- if not Path (file_path ).exists ():
22
- raise FileNotFoundError (f"File not found: { file_path } " )
23
- if platform .system () == "Darwin" :
24
- os .system ("qlmanage -p {}" .format (file_path ))
25
- elif platform .system () == "Windows" :
26
- os .startfile (file_path )
27
- elif platform .system () == "Linux" :
28
- os .system ("xdg-open {}" .format (file_path ))
29
- else :
30
- print ("Sorry, your platform is not supported." )
21
+ try :
22
+ if not Path (file_path ).exists ():
23
+ raise FileNotFoundError (f"File not found: { file_path } " )
24
+ if platform .system () == "Darwin" :
25
+ subprocess .check_call (["qlmanage" , "-p" , file_path ])
26
+ elif platform .system () == "Windows" :
27
+ os .startfile (file_path )
28
+ elif platform .system () == "Linux" :
29
+ subprocess .check_call (["xdg-open" , file_path ])
30
+ else :
31
+ raise RuntimeError ("Sorry, your platform is not supported." )
32
+ except subprocess .CalledProcessError as err :
33
+ raise RuntimeError (
34
+ f"Error occurred while opening the PDF file. Return code: { err .returncode } . Error: { err .output } "
35
+ )
31
36
32
37
33
38
def open_folder (folder_path ):
0 commit comments