Situatie
Fortunately the web browsers have been created to protect the client environment from executing client processes and accessing client resources. However sometimes this limitation is too strong and does not let us to do some simple things like direct print a document without opening an intermediate print pop-up.
Solutie
Pasi de urmat
Direct printing using browser options
Requirements:
- A compatible web browser (Firefox or Chrome).
- Direct access to the user browser.
Pros:
- You don’t need to have a web server running on the same machine.
- The web application can be remote.
- You can print what you see in the browser using just HTML and CSS.
Cons:
- You need to create a web layout for a document with HTML and CSS.
- You don’t have access to all printer options.
- Limited number of supported browsers.
- You must have access to the web browser to change configuration.
Details: In this case we have to modify the preferences of the web browser and/or execute it in a particular mode (like kiosk mode for example). As you know, every browser has a different configuration… From the web side we can use the Javascript window.print()
function. Use the following instructions based on the web browser you are using:
- Chrome You need to have Chrome version 18.0.1 or higher. From Chrome, open a new tab and type
info:config
then make sure the Disable Print Preview flag is NOT enabled (Print preview must be enabled for Kiosk Printing to work). Now set your application the default page to open when Chrome launches and then close the browser. Now you have to execute Chrome in kiosk mode. To do it just append--kiosk --kiosk-printing
to the chrome executable. Chrome should now start in kiosk mode (full-screen) and from here you should be able to print directly from the browser. - Firefox In Firefox open a new tab and type
about:config
in the address bar. Then right click on the white space and select NEW > BOOLEAN and in the text edit that appears typeprint.always_print_silent
, hit OK and then selecttrue
. This procedure writes a line to prefs.js file (on Windows) or user.js file on Linux and the next time you start the browser, any Javascript print(); function will print directly to the printer using the currently configured print settings.
You can use the following test page to test the direct printing using browser options:
<DOCTYPE html>
<html lang=” en”>
</head>
<body>
<h1>Print this page example</h1>
<p>How to Print a Test Page </p>
<button onclick=”javascript:window.print();”>Print this page</button>
</body>
</html>
Leave A Comment?