HTML/Javascript 一键打印(无对话框) [英] HTML / Javascript One Click Print (no dialogs)

查看:30
本文介绍了HTML/Javascript 一键打印(无对话框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能绕过打印对话框的打印选项?

Is it possible to have a print option that bypasses the print dialog?

我在封闭系统上工作,希望能够预定义打印对话框设置;并在我点击按钮后立即处理打印.

I am working on a closed system and would like to be able to pre-define the print dialog settings; and process the print as soon as I click the button.

根据我所阅读的内容,每个浏览器的执行方式各不相同.例如,IE 将使用 ActiveX.Chrome/Firefox 需要扩展.基于此,看来我必须用 C++ 编写一个应用程序,该应用程序可以处理浏览器传递的参数,以使用正确的格式(标签)自动打印.然后我将不得不将其重写为 Chrome/Firefox 的扩展.最终结果是,我们封闭系统上的用户必须根据他们使用的浏览器下载/安装这些功能.

From what I am reading, the way to do this varies for each browser. For example, IE would use ActiveX. Chrome / Firefox would require extensions. Based on this, it appears I'll have to write an application in C++ that can handle parameters passed by the browser to auto print with proper formatting (for labels). Then i'll have to rewrite it as an extension for Chrome / Firefox. End result being that users on our closed system will have to download / install these features depending on which browser they use.

我希望有另一种方法可以解决这个问题,但这项任务很可能会违反浏览器安全问题.

I'm hoping there is another way to go about this, but this task most likely violates browser security issues.

推荐答案

我最终实现了一个与 Nexus Mod Manager 非常相似的自定义应用程序.我编写了一个 C# 应用程序,它注册了一个自定义的 Application URI Scheme.这是它的工作原理:

I ended up implementing a custom application that works very similar to the Nexus Mod Manager. I wrote a C# application that registers a custom Application URI Scheme. Here's how it works:

  1. 用户在网站上点击打印".
  2. 网站将用户链接到CustomURL://Print/{ID}
  3. 应用程序由 windows 通过自定义 uri 方案启动.
  4. 应用程序与预配置的服务器通信以确认打印请求,并在我的情况下获取实际的打印命令.
  5. 然后应用程序使用 C# RawPrinterHelper 类直接向打印机发送命令.
  1. User clicks "Print" on the website.
  2. Website links user to "CustomURL://Print/{ID}
  3. Application is launched by windows via the custom uri scheme.
  4. Application communicates with the pre-configured server to confirm the print request and in my case get the actual print command.
  5. The application then uses the C# RawPrinterHelper class to send commands directly to the printer.

这种方法需要用户进行初始下载,并且在首次启动应用程序时需要来自 Windows 的单一安全提示.我还实现了一些 Javascript 魔法,让它检测打印作业是否被处理.如果不是,它会要求他们下载应用程序.

This approach required an initial download from the user, and a single security prompt from windows when launching the application the first time. I also implemented some Javascript magic to make it detect whether the print job was handled or not. If it wasn't it asks them to download the application.

这篇关于HTML/Javascript 一键打印(无对话框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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