Hello dears!

Today we’re gonna write about client side printing for the web users.
A lot of people are having issues when printing to POS printers, or when they need to print on specific printer without any dialogs.

So this new repos will help a lot of users to list the printers, and print on a predefined printer. Usually without this plugin, you will be using the default browser printing functionality, and it will open a dialog to select the printer.

It’s also a headache when you need to select many printers, like the A4 documents goes to HP printer, and the labels to Datamax printer. This plugin will help and make it so easy for you.

Install the plugin

Download the setup file from this link. Then install it on the client machine. This plugin must be dispatched to all users when using it in enterprise companies.

Add sample code, integrate with your web app

Include the script files

<script type="text/javascript" src="https://raw.githubusercontent.com/HusseinTaha/universal-printing/master/WebTest/Scripts/blob-util.min.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/HusseinTaha/universal-printing/master/WebTest/Scripts/fileprint.api.js"></script>
Initializing the file print setup

var fileprint = new FilePrint(0 /*timeout for closing*/, false /*useBinary for getting the file.*/, 
function ready() {

}, function erroResult(error) {

});
fileprint.setup();

List printers

fileprint.getPrinters(function listprinters(data) {
   fillPrinters(data.list);//method to create a select list with the printers.
});

Print the file

//print pdf file.
fileprint.printPDF(strPrinterName, 'http://localhost:7665/test.pdf', true/*raw-printing*/);
//print html file or some inner html data
fileprint.printHTML(strPrinterName, 'http://localhost:7665/test.html', false/*raw-printing*/, false, '-l 0.11 -r 0.05'/*margins of the paper*/);
//print image.
fileprint.printIMAGE(strPrinterName, 'http://localhost:7665/test.jpg', "jpg", true/*raw-printing*/, 200/*width*/, 100/*height*/);
//print word file
fileprint.printWORD(strPrinterName, 'http://localhost:7665/test.docx', "docx", false/*raw-printing*/);

Close the connection once done

fileprint.close();

NB: It’s very important to close the plugin after done printing. You don’t want to end up with many processes running in the background.

And finally, for contribution or getting the full source code: please check the github repo.