我正在尝试在 mac-os 中打开 pdf 到特定页面并以编程方式缩放。 但我无法这样做。 这是我的 Windows 代码,有人可以让我知道我需要在 mac-os 中更改什么吗?
import subprocess
path_to_pdf = os.path.abspath(f'F:\\Books\\{Book}.pdf')
path_to_acrobat = os.path.abspath('C:\\Program Files (x86)\\Adobe\\Acrobat 11.0\\Acrobat\\Acrobat.exe')
process = subprocess.Popen([path_to_acrobat, '/A', f'page={page_num}&zoom={zoom}', path_to_pdf], shell=False, stdout=subprocess.PIPE)
process.wait()
import os
import subprocess
# Define the PDF path, page number, and zoom level
book = "YourBookTitle" # Replace with your actual book title
page_num = 2 # Replace with your desired page number
zoom = 150 # Replace with your desired zoom level (in percentage)
path_to_pdf = os.path.abspath(f'/path/to/Books/{book}.pdf') # Replace with the actual path
# AppleScript to open the PDF in Preview and set the page and zoom
script = f"""
tell application "Preview"
open POSIX file "{path_to_pdf}"
delay 1
set the bounds of the front window to {zoom}
tell application "System Events"
keystroke "g" using {{"command down", "shift down"}}
delay 0.5
keystroke "{page_num}"
delay 0.5
keystroke return
end tell
end tell
"""
# Run the AppleScript using osascript
process = subprocess.Popen(['osascript', '-e', script], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode == 0:
print(f"Successfully opened {path_to_pdf} to page {page_num} at {zoom}% zoom")
else:
print(f"Failed to open PDF: {stderr.decode('utf-8')}")