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

查看:511
本文介绍了将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天全站免登陆