Different papers sizes on Zebra printers


I'm trying to print labels with Zebra Browser Print. What I'm trying to figure out is how to support different papers size for printing the same label. Any ideas to achieve this ?
var available_printers = null;
var selected_category = null;
var default_printer = null;
var selected_printer = null;
var format_start = "^XA^LL200^FO80,50^A0N36,36^FD";
var format_end = "^FS^XZ";
var default_mode = true;        
var labelText = "^XA^PW400^LL400^PON^FO0,10^A0,20,20^FD" + firstLine
                      + "^FS^FO0,50^A0,15,15^FD" + secondLIne +      "^FS^FO0,90^A0,15,15^FD,"
                      + thirdLine + "," + "^FS^FO0,130^A0,15,15^FD" + fourthLine
                      + "^FS^FO0,150^A0,15,15^FD" + fifthLine + "^FS"
                      + "^FO0,180^BY3^B8N,50,Y,N^FD"+barcode+"^FS"
                      + "^XZ";
function sendData(sDivText)
checkPrinterStatus(function (text) {
    selected_printer.send(format_start + sDivText + format_end,  printComplete, printerError);

Submitted by Manuel Caicedo-... on May 04, 2019 Permalink

Hi Carlo,

With the correct DPI and the correct model printer you can adjust the size of the label format to fit the paper size, so you can a have a label format for a 200 DPI, another label format for a 300 DPI, and one more for 600 DPI. You can have these as static versions or you can develop an algorithm to adjust them in running time. With the printer model you easily can identify the maximum print width, so if this printer is a 2", 3", 4" or 6" width.

How can you identify the DPI of the printer, and the model of the printer?  Ok, there is a simple ZPL command that allows you to define what type of printer and dpi you have. "~HI". More information in how to use this command. Please, go the link below pag. 196.


You could also use a SGD command like the "head.resolution.in_dpi", but it only works for Link-OS printers. Page 717, in the ZPL programming guide.

The advantage of Browser Print driver is the bi-directional capability, so you can make these requests to the printer, and the printer will give you the information you need for solving the problem. The below JavaScript function will help you to implement the logic you need to difference the dpi and send the right label format to the printer you are using at that moment. You can infere how we use the JavaScript function to implement the checking Printer status.

sendThenRead(dataToSend, finishedCallback, errorCallbackopt)
Send data to the device, then read a response back



The data to be sent to the device


The function that is called when reading is completed.

The function that is called when an error occurs while sending or reading data.

BrowserPrint-1.0.4.js, line 194

Here an example with the command "~HQES":

function checkPrinterStatus(finishedFunction)
  var that = this;
  var statuses = new Array();
  var ok = false;
  var is_error = text.charAt(70);
  var media = text.charAt(88);
  var head = text.charAt(87);
  var pause = text.charAt(84);
  // check each flag that prevents printing
  if (is_error == '0')
  ok = true;
  statuses.push("Ready to Print");
  if (media == '1')
  statuses.push("Paper out");
  if (media == '2')
  statuses.push("Ribbon Out");
  if (media == '4')
  statuses.push("Media Door Open");
  if (media == '8')
  statuses.push("Cutter Fault");
  if (head == '1')
  statuses.push("Printhead Overheating");
  if (head == '2')
  statuses.push("Motor Overheating");
  if (head == '4')
  statuses.push("Printhead Fault");
  if (head == '8')
  statuses.push("Incorrect Printhead");
  if (pause == '1')
  statuses.push("Printer Paused");
  if ((!ok) && (statuses.Count == 0))
  statuses.push("Error: Unknown Error");
  }, printerError);