Overview:

In barcode printer system applications, the B/S model, i.e. the Browser/Server architecture, is a commonly used approach.

Previously, the usual method was to use an ActiveX control, i.e. an OCX control, which allowed the IE browser to call print control functions like calling a DLL, controlling printer output and obtaining return data from the printer. But using OCX has an obvious drawback: it only supports IE, not Firefox, Chrome, or even Edge, and it cannot be used on Android or Apple devices either.

To address this, we introduced this web-based print service: ZMPrintService. It uses the HTML5 WebSocket API and can perfectly replace OCX. Moreover, even if you have already developed a system with OCX, you only need to modify a small amount of code to convert it.

ZMPrintService supports ZMPCL.dll functions, so you can easily control the printer from a web page, support printing 1D barcodes, 2D barcodes, text, images, etc., support reading and writing RFID labels, and also enable print preview. It is powerful and practical.

It is compact and efficient, with a simple interface, easy setup and high processing efficiency, suitable for fast preview or label printing from web pages.

System requirements:

1. Running ZMPrintService requires the .NET 4.5 runtime environment;

2. The web browser must support HTML5;

3. WinXP does not support .NET 4.5, so ZMPrintService only supports Windows 7 and later operating systems..

Usage steps:

1. Run ZMPrintService.exe; the software will automatically minimize to the system tray in the lower right corner.

2. Right-click the system tray icon to show the main interface, create a desktop shortcut, set it to start automatically at boot, or exit the software (note that clicking the X button on the software interface will only minimize it, not exit the software).

3. The main interface allows you to change the service port number and print direction; changes take effect immediately.

4. Web pages can only preview and print normally after ZMPrintService.exe is running; it is recommended to set it to start automatically at boot.

5. Other computers, mobile phones, iPads, etc. on the same LAN can use a browser to remotely access the IP of the computer connected to the printer for network printing.

Precautions:

1. ZMPrintService.zip must be extracted to a specified directory.

2. On Windows 10, using IE or Edge may fail to connect to the print backend due to security settings; make the following settings:

1) Open Control Panel -> Internet Options;

2) In the "Internet Properties" window that appears, select the "Security" tab;

3) In the box under "Select a zone to view or change security settings", select "Local intranet";

4) Click the "Sites" button to the right of "Local intranet";

5) In the "Local intranet" window that appears, clear all check boxes and click "OK";

6) Close the "Internet Properties" window; the print backend can now be connected normally.

Function description:

Due to browser security restrictions, web pages cannot directly operate barcode printer devices; a browser-specific plug-in must be developed. However, there are many browsers, and developing a plug-in for each one is unrealistic, with huge workload and difficult maintenance.

The WebSocket API is the next-generation client-server asynchronous communication method. It replaces a single TCP socket, uses the ws or wss protocol, and can be used for any client and server program. WebSocket is currently being standardized by the W3C. WebSocket is already supported by Firefox 4, Chrome 4, Opera 10.70, Safari 5 and their later versions.

The greatest thing about the WebSocket API is that the server and client can push information to each other at any time within a given time range. WebSocket is not limited to Ajax (or XHR) communication, because Ajax requires the client to initiate a request, whereas WebSocket servers and clients can push information to each other; XHR is restricted by domain, while WebSocket allows cross-domain communication.

Therefore, you can think of ZMPrintService.exe as a bridge between web pages and the printer.

It receives information sent from the web page. If interaction with the printer is required, it calls the corresponding functions in the DLL to control the printer and sends the result back to the web page for further processing.

So web printing and DLL printing use the same functions; only the calling method differs. For detailed DLL function descriptions, please refer to the file "ZMPCL_DLL_Function_Description_V****.pdf".

For example, in C# we call DLL functions like this:

int errorcode = ZMPCL.OpenPort(255);//Open the printer on the USB port of the current computer; no driver installation is required

if (errorcode != 0) {

MessageBox.Show("Error opening the printer USB port, the code is: " + errorcode.ToString() + "\r\nError opening the printer USB port, the code is:" + errorcode.ToString());return;}

ZMPCL.ZM_ClearBuffer();//Clear the buffer

ZMPCL.ZM_SetPrintSpeed(4);//Set print speed

ZMPCL.ZM_SetDarkness(10);//Set print darkness

ZMPCL.ZM_SetLabelWidth(400);//Set label width

ZMPCL.ZM_SetLabelHeight(800, 16);//Set label height and gap

In the web page, we change it to this:

wsocket.send('OpenPort|255');//Open the port. If opening fails, ZMPrintService returns the error code to the web page; the web page must handle it and stop sending further function commands.

wsocket.send('ZM_ClearBuffer');//Clear

wsocket.send('ZM_SetPrintSpeed|4');//Set speed

wsocket.send('ZM_SetDarkness|10');//Set darkness

wsocket.send('ZM_SetLabelWidth|400');//Set label width

wsocket.send('ZM_SetLabelHeight|800|16');//Set label height and gap

The format inside the wsocket.send function is as follows:

wsocket.send('function name in DLL|parameter 1|parameter 2|parameter 3');

The function name and parameters are separated by vertical bars "|". If the printed content needs to use "|", escape it as "||".

Note:

«ZMPrintService does not parse all ZMPCL.dll functions, only most commonly used ones. If you need a function that ZMPrintService does not yet support, please contact us to add it.

«In all functions, coordinate, width, height and other parameters are in dots. The formula for converting millimeters (mm) to dots is as follows:

mm * printerDPI / 25.4;//Convert mm to dots; the printer's print resolution must be known

In addition to supporting ZMPCL.dll functions, ZMPrintService also defines the following custom functions:

1. Preview label: ZM_PrintLabel_Preview

Call format:

wsocket.send('ZM_PrintLabel_Preview|203|0|1');//Preview the label.

Parameter 1 is the printer resolution; parameter 2 is the image width (height is scaled proportionally automatically), and a value of 0 means the original size; parameter 3 is the border thickness, and 0 means no border.

After this function is called, it returns the Base64 string of the label image in the following format:

ZM_PrintLabel_Preview:Base64-encoded string of the label image

Process the received image data in the web page's wsocket.onmessage = function(receiveMsg) (receives data returned by the server) function.

if(receivecontent.startsWith("ZM_PrintLabel_Preview:")) { //Returned label preview image data

var imagebase64string=receivecontent.replace("ZM_PrintLabel_Preview:","");

document.getElementById("pvimg").src = imagebase64string;//Assign the Base64 string data of the image

}

2. Print an image (Base64-encoded string): PrintBase64Image

Call format:

wsocket.send(' PrintBase64Image|24|24|Base64-encoded string of the image');

or

wsocket.send(' PrintBase64Image|24|24|120|60|Base64-encoded string of the image');//Specify the image width and height

(1) Parameters without specifying image width and height:

Parameter 1 is the starting X coordinate of the image's top-left corner; parameter 2 is the starting Y coordinate of the image's top-left corner; parameter 3 is the Base64-encoded string of the image.

(2) Parameters specifying image width and height:

Parameter 1 is the starting X coordinate of the image's top-left corner; parameter 2 is the starting Y coordinate; parameter 3 is the image width; parameter 4 is the image height; parameter 5 is the Base64-encoded string of the image.

No return value.

3. Read printer model and serial number: ZM_GetPrinterNameAndSN

Call format:

wsocket.send('ZM_GetPrinterNameAndSN');

No parameters.

After this function is called, it returns the name, port number and serial number of the currently connected printer. If there are multiple printers, they are separated by "||", in the following format:

Printer model name,USB port number,mainboard serial number (||printer model name,USB port number,mainboard serial number)

4. Write NDEF-format URL: ZM_HF_RW_NDEFURL

Note: This function is only supported by RFID HF label printers.

Call format:

wsocket.send('ZM_HF_RW_NDEFURL|URL');

Parameter 1 is the URL to be written, starting with http:// or https://.

No return value.

5. Write NDEF-format text: ZM_HF_RW_NDEFTEXT

Note: This function is only supported by RFID HF label printers.

Call format:

wsocket.send(' ZM_HF_RW_NDEFTEXT |text');

Parameter 1 is the text to be written.

No return value.

2021-09-10