我正在编写一个脚本,自动在Chrome中打印一组网页。如果我要手动打印它们,我会从“比例”下拉菜单中选择“自定义”,并在下面的输入字段中输入50。
我无法确定在使用ChromeDriver自动批量打印这些页面时传递哪些参数来复制此设置。
appState = { "recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": "",
"printing.scaling": 'Custom', # <== Does it go here?
}],
"selectedDestinationId": "Save as PDF",
"version": 2,
"printing.scaling": 'Custom', # <== Or here?
}
profile = { 'printing.print_preview_sticky_settings.appState': json.dumps(appState),
'printing.print_header_footer': False,
# So many different versions of things I have tried :-(
'printing.scaling': 'Custom',
'printing.scaling_type': 'Custom',
'print_preview.scaling': 'Custom',
'print_preview.scaling_type': 'Custom',
'printing.custom_scaling': True,
'printing.fit_to_page_scaling': 50,
'printing.page_scaling': True,
}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
br = webdriver.Chrome(options=chrome_options)
在阅读了大量Chromium源代码并试图获取提示后,上述所有不同的选项都是猜测。
https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup https://chromium.googlesource.com/chromium/src/+/master/printing/print_job_constants.cc https://chromium.googlesource.com/chromium/src/+/master/printing/print_job_constants.h
我没有线索了。接下来我该尝试什么?
scalingType
后面有一个错误的方括号。这样我就不能只编辑那个了。 - jeverling