4

I am using ChromeDriver 2.33 and am using kiosk printing to automatically click the Print button on the Print Preview dialog however it is sending the document to the printer instead of PDF.

I have attempted the solution at this stack overflow question to no avail.

Here is the code I am using:

ChromeOptions o = new ChromeOptions();
o.AddArgument("--kiosk-printing");
o.AddUserProfilePreference("printing.print_preview_sticky_settings.appState", "{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"");
chrome = new ChromeDriver(dir, o);

Can anyone tell me how I set the printer to PDF from the actual printer?

Gokul
  • 788
  • 2
  • 12
  • 30
Elliot
  • 93
  • 1
  • 1
  • 11
  • I tried all kinds of stuff to get Selenium to work with "--kiosk-printing" but I couldn't get it to work. Instead I did this, which did work: https://stackoverflow.com/questions/50166936/how-to-print-to-pdf-using-node-js-webdriver-io-chimp – Ryan Shillington May 04 '18 at 04:07

1 Answers1

6

try adding Save as PDF on recentDestinations:

import json
settings = {
    "appState": {
        "recentDestinations": [{
            "id": "Save as PDF",
            "origin": "local"
        }],
        "selectedDestinationId": "Save as PDF",
        "version": 2
    }  
}
prefs = {'printing.print_preview_sticky_settings': json.dumps(settings)}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', prefs)
chrome_options.add_argument('--kiosk-printing')

driver = webdriver.Chrome(chrome_options=chrome_options)
Phablulo Joel
  • 309
  • 3
  • 5
  • 4
    Using the latest version of Chrome (78.0.3904.108), need to add `"account": ""` to `"recentDestinations"`. – TAH Nov 19 '19 at 20:29