1

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

Shubham
  • 57
  • 1
  • 13
  • were you able to achieve this? – Ab1gor May 17 '19 at 12:37
  • No, this code is not working with latest version of Google Chrome and chromedriver so i installed Chrome version 62 and it worked with it. – Shubham May 20 '19 at 04:15
  • @Shubham Does not work for me either. Have not downloaded older version of Chrome as you have done, but am wondering if can save complete html page and then convert to pdf. But have not figured that out either... – jim70 Jul 06 '19 at 01:34

1 Answers1

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,
           }
TAH
  • 1,658
  • 1
  • 19
  • 37