import sys import subprocess import tempfile import os def open_with_system_viewer(pdf_data): with tempfile.NamedTemporaryFile(suffix='.pdf', delete=False) as f: f.write(pdf_data) temp_path = f.name # 打开系统默认阅读器 if sys.platform.startswith('darwin'): # macOS subprocess.call(('open', temp_path)) elif os.name == 'nt': # Windows os.startfile(temp_path) elif os.name == 'posix': # Linux subprocess.call(('xdg-open', temp_path))