直接从浏览器打印,无需打印弹出窗口[重复]

时间:2022-02-25 21:02:31

This question already has an answer here:

这个问题在这里已有答案:

As it said in the subject I've to create a feature for a web-based application that will allow users to send print directly without prompting any dialog boxe just make the print i.e click and print, simple! but not for me :(.

正如它在主题中所说,我将为基于Web的应用程序创建一个功能,允许用户直接发送打印而不提示任何对话框只需进行打印即点击和打印,简单!但不适合我:(。

Please, suggest what would be the best option and how should I write it up (technology).

请,建议什么是最好的选择,我应该怎么写(技术)。

Suggest please!

Thanks.

EDIT: The print should be send on the user's default printer.

编辑:打印应该在用户的默认打印机上发送。

7 个解决方案

#1


I couldn't find solution for other browsers. When I posted this question, IE was on the higher priority and gladly I found one for it. If you have a solution for other browsers (firefox, safari, opera) please do share here. Thanks.

我找不到其他浏览器的解决方案。当我发布这个问题时,IE的优先级更高,很高兴我找到了一个。如果你有其他浏览器的解决方案(firefox,safari,opera),请在这里分享。谢谢。

VBSCRIPT is much more convenient than creating an ActiveX on VB6 or C#/VB.NET:

VBSCRIPT比在VB6或C#/ VB.NET上创建ActiveX要方便得多:

<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

Now, calling:

<a href="javascript:window.print();">Print</a>

will send print without popup print window.

将发送没有弹出打印窗口的打印。

#2


AttendStar created a free add-on that suppresses the print dialog box and removes all headers and footers for most versions of Firefox.

AttendStar创建了一个免费的附加组件,可以抑制打印对话框,并删除大多数Firefox版本的所有页眉和页脚。

https://addons.mozilla.org/en-US/firefox/addon/attendprint/

With that feature on you can use $('img').jqprint(); and jqprint for jquery will only print that image automatically called from your web application.

使用该功能,您可以使用$('img')。jqprint(); jquery的jqprint只会打印从Web应用程序自动调用的图像。

#3


IE9 no longer supports triggering the Print() VBScript by calling window.print() like IE7 and IE8 do, and thus window.print() will now always trigger the print dialog in IE9.

IE9不再支持通过调用window.print()来触发Print()VBScript,就像IE7和IE8一样,因此window.print()现在总是会触发IE9中的打印对话框。

The fix is pretty simple. You just need to call Print() itself, instead of window.print() in the onclick event.

修复非常简单。您只需要调用Print()本身,而不是onclick事件中的window.print()。

I've described the fix in more detail in an answer to another question, with a working code example sporting slightly updated HTML syntax (as much as possible while still tested as working code).

我在另一个问题的答案中更详细地描述了这个修复,其中一个工作代码示例运行略微更新的HTML语法(尽可能地尽可能地测试为工作代码)。

You can find that sample code here:

你可以在这里找到示例代码:

Bypass Printdialog in IE9

在IE9中绕过Printdialog

#4


I don't believe this is possible. The dialog box that gets displayed allows the user to select a printer to print to. So, let's say it would be possible for your application to just click and print, and a user clicks your print button, but has two printers connected to the computer. Or, more likely, that user is working in an office building with 25 printers. Without that dialog box, how would the computer know to which printer to print?

我不相信这是可能的。显示的对话框允许用户选择要打印的打印机。因此,假设您的应用程序可以单击并打印,用户单击您的打印按钮,但有两台打印机连接到计算机。或者,更有可能的是,该用户正在拥有25台打印机的办公楼中工作。如果没有该对话框,计算机将如何知道要打印哪台打印机?

#5


this.print(false);

I tried this in Chrome, Firefox and IE. It works only in Firefox and IE, it uses the default printer (with default print settings) and only works when I render a PDF (I use Foxit Reader with Safe Reading Mode disabled). Chrome shows the print dialog, also the other browsers when I render an HTML page.

我在Chrome,Firefox和IE中试过这个。它仅适用于Firefox和IE,它使用默认打印机(默认打印设置),仅在我渲染PDF时使用(我使用福昕阅读器禁用安全阅读模式)。 Chrome会在呈现HTML页面时显示打印对话框以及其他浏览器。

#6


For IE browsers, the "VBScript solution" works.

对于IE浏览器,“VBScript解决方案”有效。

But as mentioned by @purefusion at Bypass Printdialog in IE9, Use Print() rather than window.print()

但正如@purefusion在IE9中的Bypass Printdialog中所提到的,使用Print()而不是window.print()

#7


This should work, I tried it by myself and it worked for me. If you pass True instead of false, the print dialog will appear.

这应该工作,我自己尝试,它对我有用。如果传递的是True而不是false,则会出现打印对话框。

this.print(false);

#1


I couldn't find solution for other browsers. When I posted this question, IE was on the higher priority and gladly I found one for it. If you have a solution for other browsers (firefox, safari, opera) please do share here. Thanks.

我找不到其他浏览器的解决方案。当我发布这个问题时,IE的优先级更高,很高兴我找到了一个。如果你有其他浏览器的解决方案(firefox,safari,opera),请在这里分享。谢谢。

VBSCRIPT is much more convenient than creating an ActiveX on VB6 or C#/VB.NET:

VBSCRIPT比在VB6或C#/ VB.NET上创建ActiveX要方便得多:

<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

Now, calling:

<a href="javascript:window.print();">Print</a>

will send print without popup print window.

将发送没有弹出打印窗口的打印。

#2


AttendStar created a free add-on that suppresses the print dialog box and removes all headers and footers for most versions of Firefox.

AttendStar创建了一个免费的附加组件,可以抑制打印对话框,并删除大多数Firefox版本的所有页眉和页脚。

https://addons.mozilla.org/en-US/firefox/addon/attendprint/

With that feature on you can use $('img').jqprint(); and jqprint for jquery will only print that image automatically called from your web application.

使用该功能,您可以使用$('img')。jqprint(); jquery的jqprint只会打印从Web应用程序自动调用的图像。

#3


IE9 no longer supports triggering the Print() VBScript by calling window.print() like IE7 and IE8 do, and thus window.print() will now always trigger the print dialog in IE9.

IE9不再支持通过调用window.print()来触发Print()VBScript,就像IE7和IE8一样,因此window.print()现在总是会触发IE9中的打印对话框。

The fix is pretty simple. You just need to call Print() itself, instead of window.print() in the onclick event.

修复非常简单。您只需要调用Print()本身,而不是onclick事件中的window.print()。

I've described the fix in more detail in an answer to another question, with a working code example sporting slightly updated HTML syntax (as much as possible while still tested as working code).

我在另一个问题的答案中更详细地描述了这个修复,其中一个工作代码示例运行略微更新的HTML语法(尽可能地尽可能地测试为工作代码)。

You can find that sample code here:

你可以在这里找到示例代码:

Bypass Printdialog in IE9

在IE9中绕过Printdialog

#4


I don't believe this is possible. The dialog box that gets displayed allows the user to select a printer to print to. So, let's say it would be possible for your application to just click and print, and a user clicks your print button, but has two printers connected to the computer. Or, more likely, that user is working in an office building with 25 printers. Without that dialog box, how would the computer know to which printer to print?

我不相信这是可能的。显示的对话框允许用户选择要打印的打印机。因此,假设您的应用程序可以单击并打印,用户单击您的打印按钮,但有两台打印机连接到计算机。或者,更有可能的是,该用户正在拥有25台打印机的办公楼中工作。如果没有该对话框,计算机将如何知道要打印哪台打印机?

#5


this.print(false);

I tried this in Chrome, Firefox and IE. It works only in Firefox and IE, it uses the default printer (with default print settings) and only works when I render a PDF (I use Foxit Reader with Safe Reading Mode disabled). Chrome shows the print dialog, also the other browsers when I render an HTML page.

我在Chrome,Firefox和IE中试过这个。它仅适用于Firefox和IE,它使用默认打印机(默认打印设置),仅在我渲染PDF时使用(我使用福昕阅读器禁用安全阅读模式)。 Chrome会在呈现HTML页面时显示打印对话框以及其他浏览器。

#6


For IE browsers, the "VBScript solution" works.

对于IE浏览器,“VBScript解决方案”有效。

But as mentioned by @purefusion at Bypass Printdialog in IE9, Use Print() rather than window.print()

但正如@purefusion在IE9中的Bypass Printdialog中所提到的,使用Print()而不是window.print()

#7


This should work, I tried it by myself and it worked for me. If you pass True instead of false, the print dialog will appear.

这应该工作,我自己尝试,它对我有用。如果传递的是True而不是false,则会出现打印对话框。

this.print(false);