Set up raw printing for thermal and label printers ​

Raw printing sends commands to a printer in its own language, for example ESC/POS or ZPL. Thermal receipt printers and barcode label printers use these commands. Raw printing skips most printer drivers, so it is fast. It can also cut receipt paper or open a cash drawer.

ERPNext sends the commands through QZ Tray, an application that runs on the computer that the printer is connected to.

Prerequisites ​

  • The System Manager role.
  • The printer's command reference from the manufacturer.
  • A computer with Windows, macOS, or Linux that is connected to the printer.

Step 1: Install QZ Tray ​

  1. On the computer that is connected to the printer, download QZ Tray from the QZ website.
  2. Install it. If the installer asks for Java, install Java too.

For help with the installation, read the QZ Tray documentation.

Step 2: Create a raw commands print format ​

  1. Open the Print Format list, and select New.
  2. Enter a name, and select the DocType.
  3. Select Custom Format, and then select Raw Printing.
  4. In Raw Commands, enter the printer commands. You can use Jinja tags, as in an HTML print format.
  5. Select Save.

Step 3: Turn on raw printing ​

  1. Open Print Settings.
  2. In the Raw Printing section, select Enable Raw Printing.
  3. Select Save.
  1. Open the document, and select the Print icon.
  2. Select the raw commands print format. The preview shows "No Preview available".
  3. Select Print.
  4. In the QZ Tray prompt, allow the connection.
  5. If ERPNext asks for a printer, map the print format to a printer that is installed on the computer.

ERPNext stores the print format to printer mapping in the browser of that computer. Set it on each computer. To change it, select Printer Settings in the print view.

To print on an event, such as on submit, call the raw print functions from a client script.

FunctionWhat it does
frappe.ui.form.qz_connect()Connects to QZ Tray. Returns a promise. You can call it before every print.
frappe.ui.form.qz_get_printer_list()Returns a promise that resolves to the list of printer names.
frappe.ui.form.qz_success()Shows the "Print Sent to the printer!" alert.
frappe.ui.form.qz_fail(err)Shows the error message. Call it when the connection fails.
js
frappe.ui.form
	.qz_connect()
	.then(function () {
		// config and data follow the qz-tray.js API
		return qz.print(config, data);
	})
	.then(frappe.ui.form.qz_success)
	.catch((err) => {
		frappe.ui.form.qz_fail(err);
	});

qz is the global object of the qz-tray.js library. ERPNext creates it the first time that you call qz_connect. To get it earlier, call frappe.ui.form.qz_init(). For the full API, read the qz-tray.js API documentation.