将 Selenium ChromeDriver UserPreferences 设置为另存为 PDF [英] Set Selenium ChromeDriver UserPreferences to Save as PDF

查看:41
本文介绍了将 Selenium ChromeDriver UserPreferences 设置为另存为 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ChromeDriver 2.33 并且正在使用自助服务终端打印来自动单击打印预览"对话框上的打印"按钮,但是它将文档而不是 PDF 发送到打印机.

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.

我在 这个堆栈溢出问题无济于事.

这是我正在使用的代码:

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);

谁能告诉我如何将打印机从实际打印机设置为 PDF?

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

推荐答案

尝试在 recentDestinations 上添加 Save as PDF:

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)

这篇关于将 Selenium ChromeDriver UserPreferences 设置为另存为 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆