我正在尝试创建一个脚本,通过Chrome的打印功能自动保存只读pdf,以将其另存为同一文件夹中的另一个pdf。这将删除“只读”'特征。但是,在运行脚本时,我不确定在哪里可以指定自己的特定目标文件夹,脚本会直接将其保存在“下载”文件夹中。
非常感谢任何帮助。
import json
from selenium import webdriver
downloadPath = r'mypath\downloadPdf\'
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local"
}
],
"selectedDestinationId": "Save as PDF",
"version": 2
}
profile = {'printing.print_preview_sticky_settings.appState':
json.dumps(appState)}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')
driver = webdriver.Chrome(chrome_options=chrome_options)
pdfPath = r'mypath\protected.pdf'
driver.get(pdfPath)
driver.execute_script('window.print();')