Using Selenium and ChromeDriver, automatically scale the size of the page on print

739 views
Skip to first unread message

TAH

unread,
Nov 21, 2019, 1:07:03 AM11/21/19
to Chromium-discuss
I'm writing a script to automatically print a set of web pages in Chrome. If I were to print them manually, I'd choose "Custom" from the Scale drop down and enter 50 into the input field below.


I can't figure out what arguments to pass in to replicate this setting when I automatically print these pages in bulk using Selnium with ChromeDriver.


I've tried grep'ing through the Chromium source to figure this out... but no luck.  Any ideas?  Below is what my code looks like at the moment, with a bunch of failed attempts noted.  Thank you!!!


appState = { "recentDestinations": [{
                "id": "Save as PDF",
                "origin": "local",
                "account": "",
                "printing.scaling": 'Custom', # <== Does it go here?
             }],
             "selectedDestinationId": "Save as PDF",
             "version": 2,
             "printing.scaling": 'Custom',  # <== Or here?
           }
profile = { 'printing.print_preview_sticky_settings.appState': json.dumps(appState),
            'printing.print_header_footer': False,

            # So many different versions of things I have tried :-(
            'printing.scaling': 'Custom',
            'printing.scaling_type': 'Custom',
            'print_preview.scaling': 'Custom',
            'print_preview.scaling_type': 'Custom',
            'printing.custom_scaling': True,
            'printing.fit_to_page_scaling': 50,
            'printing.page_scaling': True,
          }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
br = webdriver.Chrome(options=chrome_options)

Reply all
Reply to author
Forward
0 new messages