0

Under More settings, chrome (v96) has an option for Margins, which I have selected as none. Here are our options currently for chrome:

enter image description here

Here are our options currently, which are set so that we can save PDFs locally with Selenium:

def make_options(output_dir):
    state = {
        "recentDestinations": [
            {
                "id": "Save as PDF",
                "origin": "local",
                "account": ""
            }
        ],
        "selectedDestinationId": "Save as PDF",
        "version": 2
    }

    profile = {'printing.print_preview_sticky_settings.appState': json.dumps(state),
               'savefile.default_directory': output_dir,
               "download.default_directory": output_dir}
    chrome_options = webdriver.ChromeOptions()
    chrome_options.headless = False
    chrome_options.add_experimental_option('prefs', profile)
    chrome_options.add_argument('--kiosk-printing')
    return chrome_options

I can see in the PDFs saved with Selenium that Margins is not set to None. Is it possible to update the code above for this? We need Margins: None in the chrome options, setting it in the CSS of the webpage we are saving as PDF does not resolve our issue.

Canovice
  • 9,012
  • 22
  • 93
  • 211

1 Answers1

0

You can set the margin type in the json construct, the option for no Margins is 1. see this link https://github.com/chromium/chromium/blob/eadef3f685cd9e96e94fcb9645b6838b6d0907a8/chrome/browser/resources/print_preview/data/margins.js

edit your code to include this new line:

def make_options(output_dir):
    state = {
        "recentDestinations": [
            {
                "id": "Save as PDF",
                "origin": "local",
                "account": ""
            }
        ],
        "selectedDestinationId": "Save as PDF",
        "version": 2,
        "marginsType": 1
    }

    profile = {'printing.print_preview_sticky_settings.appState': json.dumps(state),
               'savefile.default_directory': output_dir,
               "download.default_directory": output_dir}
    chrome_options = webdriver.ChromeOptions()
    chrome_options.headless = False
    chrome_options.add_experimental_option('prefs', profile)
    chrome_options.add_argument('--kiosk-printing')
    return chrome_options
Josh Lowe
  • 1
  • 1