经过大量的搜索和试错,我终于找到了解决方案这个设置存在于appState字典中,被称为 "scalingType",但它是一个枚举,恼人的是它似乎只接受一个数字,这些数字被定义为here (Github mirror) or here (googlesource).3给你提供了自定义缩放,然后你可以在 "缩放 "设置中定义它(这是一个字符串!)。所以我的设置现在看起来像。
chrome_options = webdriver.ChromeOptions()
appState = {"recentDestinations": [{"id": "Save as PDF", "origin": "local", "account": ""}],
"selectedDestinationId": "Save as PDF",
"version": 2,
"isHeaderFooterEnabled": False,
"isLandscapeEnabled": True,
"scalingType": 3,
"scaling": "141"}
prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(appState),
'savefile.default_directory': BASE_DIR}
chrome_options.add_experimental_option('prefs', prefs)
chrome_options.add_argument('kiosk-printing')
driver = webdriver.Chrome(f'{BASE_DIR}\\chromedriver.exe', options=chrome_options)
目前缩放类型的选项是。
0: default
1: fit to page
2: fit to paper
3: custom
但我在 "适合 "选项中没有取得任何成功。
更为普遍的是,这些设置/选项中的大部分可以通过查看以下内容来确定this file的chromium源代码和/或其包含的文件夹。