16

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.

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
teynon
  • 7,540
  • 10
  • 63
  • 106
  • what did you end up using? We are trying to use firefox or chrome browser. – Reaz Patwary Mar 19 '15 at 01:58
  • @ReazPatwary We ended up using something called jZebra which is now called qz (http://qzindustries.com/download) However, I looked up / found another possible way of doing it, but it requires a client side download. This would involve the user installing an application that uses a custom protocol (https://msdn.microsoft.com/en-us/library/ie/aa767914%28v=vs.85%29.aspx) – teynon Mar 20 '15 at 02:05
  • thanks for your quick response. But Our major platform is Mac OSX. Looks like thats a .exe file for windows platform :(. – Reaz Patwary Mar 20 '15 at 15:15
  • @ReazPatwary - The qz program is a java based program. However, I would imagine that macs also support custom protocols - http://stackoverflow.com/questions/471581/how-to-map-a-custom-protocol-to-an-application-on-the-mac – teynon Mar 20 '15 at 16:36
  • **qz program** is paid to remove warnings and that too $312 USD for 1 year. Anyone knows freeware similar kind of product. – Kamaldeep Singh Jan 13 '16 at 11:19
  • @KamaldeepSingh jZebra is the original and it was free. However, I provided a method of solving this issue in my answer below similar to the Nexus Mod Manager. – teynon Jan 13 '16 at 14:44

6 Answers6

15

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. 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.

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.

teynon
  • 7,540
  • 10
  • 63
  • 106
9

I am writing this answer for firefox browser.

  • Open File > Page Setup

  • Make all the headers and footers blank

  • Set the margins to 0 (zero)

  • In the address bar of Firefox, type about:config

  • Search for print.always_print_silent and double click it

  • Change it from false to true

    • This lets you skip the Print pop up box that comes up, as well as skipping the step where you have to click OK, automatically printing the right sized slip.
  • If print.always_print_silent does not come up

    • Right click on a blank area of the preference window

    • Select new > Boolean

    • Enter "print.always_print_silent" as the name (without quotes)

    • Click OK

    • Select true for the value

  • You may also want to check what is listed for print.print_printer

    • You may have to choose Generic/Text Only (or whatever your receipt printer might be named)
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Abhijeet Kale
  • 379
  • 3
  • 13
8

I know this is a late reply, but here's a solution I'm using. I have only used this with IE, and have not tested it with any other browser.

This Sub Print blow effectively replaces the default print function.

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

Then use Javascript's window.print(); ties to a hyperlink or a button to execute the print command.

If you want to automatically print when the page loads, then put the code below near tag.

<script type="text/javascript"> 
window.onload=function(){self.print();} 
</script> 
  • 4
    VBScript will not work on any other browser, period. But it's a nice solution for IE. – eis Jan 24 '13 at 16:48
  • 2
    Just to follow up, I ended up implementing a Java app called jZebra. This app requires the first time install / security approval. https://code.google.com/p/jzebra/ – teynon Sep 16 '13 at 02:28
4

The general answer is: NO you cannot do this in the general case but there some cases where you might do it. Check http://justtalkaboutweb.com/2008/05/09/javascript-print-bypass-printer-dialog-in-ie-and-firefox/

If you where allowed to do such a thing anyway, it would be a security issue since a malware script could silently sent printing jobs to visitor's printer.

Community
  • 1
  • 1
pater
  • 1,211
  • 9
  • 16
2

I found a awesome plugin by Firefox which solve this issue. try seamless printing plugin of firefox which will print something from a web application without showing a print dialog.

  1. Open Firefox
  2. Search addon name seamless printing and install it
  3. After successful installation the printing window will get bypassed when user wants to print anything.
Reaz Patwary
  • 824
  • 2
  • 7
  • 23
-2

I was able to solve the problem with this library: html2pdf.js (https://github.com/eKoopmans/html2pdf.js)

Considering that you have access to it, you could do something like that (taken from the github repository):

var element = document.getElementById('element-to-print'); 
html2pdf(element);
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
demaroar
  • 127
  • 1
  • 4