问题
Chromedriver Save as PDF method is not working. Before it was working fine but now whenever i run this code it gets on Save as PDF Screen and actually prints the page instead of saving as PDF
I tried changing the id but it didn't worked either
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"margin": 0,
'size': 'auto'
}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
"margin": 0,
'size': 'auto'
}
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)
It should save the file as PDF instead of selecting Microsoft XPS Document Writer option and print the page This is the option it should select
回答1:
Using Chrome Version 78.0.3904.108 (Official Build) (64-bit).
Add "account": ""
to "recentDestinations"
.
appState = { "recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": "", # <======= Add this
}],
"selectedDestinationId": "Save as PDF",
"version": 2,
}
来源:https://stackoverflow.com/questions/55706083/chromedriver-save-as-pdf-method-not-working