【问题标题】:Print image with Chrome using command line switches / startup arguments使用命令行开关/启动参数使用 Chrome 打印图像
【发布时间】:2017-10-10 12:41:37
【问题描述】:

有没有办法用 Chrome 打开一个图像 url 并在启动时使用命令行开关(启动参数)打印该图像。

它可以是无头的或非无头的。打印到默认打印机也可以。

This appears to be a complete list of chrome command line switches,但我没有看到任何东西可以完全符合我的要求,尽管有大约 1,300 个选项,所以我可能会遗漏一些东西。

【问题讨论】:

    标签: google-chrome command-line printing headless-browser google-chrome-headless


    【解决方案1】:

    我发现了一个适合我特定情况的愚蠢工作。我使用的是 C#,所以这个答案是 C# 特定的,尽管您可能可以将这个想法应用于大多数语言。

    我在--kiosk, --kiosk-printing 模式下启动 chrome,这会禁用打印对话框。然后我等待chrome启动。然后我发送 CTRL + P 键。完整的方法如下所示。

    public void printImageUrlWithChrome(string url)
    {
        using (var process = new Process())
        {
            // Start Chrome in kiosk with kiosk printing (no printing confirmation window)
            process.StartInfo.FileName = Properties.Settings.Default.googleChrome;
            process.StartInfo.Arguments = url + " --kiosk --kiosk-printing";
            process.Start();
    
            // Wait for Kiosk to load
            int millisecondWaitForChrome = 1000;
            System.Threading.Thread.Sleep(millisecondWaitForChrome)
    
            // Send CTRL + p
            SendKeys.Send("^(p)");
        }
    }
    

    还是会更喜欢不那么愚蠢的解决方案,最好是只带有命令开关的解决方案。

    【讨论】:

    • 好主意!我将在 Python 中尝试一下。如何退出 --kiosk 模式?
    • @HrvojeT Ctrl + W 将关闭窗口。据我所知,您无法将信息亭模式窗口转换为正常模式。
    • Np,打印完我会杀掉Chrome
    • 如果我在 WinXP 中无法进入 kioks 模式之前打开了 Chrome。所以我模拟按 ctrl-p 然后输入 import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys("{ENTER}", 0)
    猜你喜欢
    • 2021-03-12
    • 2023-04-03
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    相关资源
    最近更新 更多