Chromedriver Save as PDF method not working

核能气质少年 提交于 2021-02-11 07:37:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!