How to print a report in ZPL format

2018-01-16

The new version of FastReport .NET 2018.1 has a new export to the ZPL (Zebra Programming Language) format. This format is designed to be used in conjunction with special label printers. More information about ZPL can be found in the article "Page description language – ZPL".

When developing reports that are supposed to be printed on a label printer, the following points should be considered:

• the page size must match the label size, you can adjust the dimensions in the report designer in the Page Setup in the Report menu;

• the fields specified in the page size setting window are also taken into account - if you need to print close to the edge of the label, you need to set the fields to 0;

• Each generated report page will be sent to the printer as a separate label;

• When drawing up a report, you should adhere to a black and white color scheme.

You can create a file with a set of ZPL commands from the preview window.

  • The Density parameter is responsible for the print density, dots per millimeter. Density is selected depending on the printer, on which the label will be printed in the future.
  • The Print As Bitmap check box indicates that a per-pixel copy of the report image will be sent to the printer. In other words, a black and white image of the report will be generated and saved as a picture in the ZPL format. If this checkbox is disabled, the report objects will be saved as a sequence of ZPL commands. Text values are stored in the UTF-8 encoding, barcodes (those that have corresponding analogs in the ZPL)  are transmitted as separate commands. It should be borne in mind that when printing a report as a picture, barcodes can be unreadable, even though they will look identical to what we got in the report. The reason for such barcode behavior is the wrong ratio of the line thickness due to the barcode object scaling. To avoid errors reading barcodes, you should disable the Print As Bitmap mode, but in this case, the appearance of barcodes may not match those that we see in the preview window.
  • The Font Scale parameter is responsible for scaling the font size.

If there is no label printer available or for economical purposes, you can test the saved file in the Online ZPL Viewer (http://www.labelary.com/viewer.html) - open the generated file with the extension *. Zpl in any text editor, copy it in the text box on the site and click the Redraw button.

You can make additional export settings in the ZPL and send it directly to the label printer from the program code. Look at the demo program in the \ Demos \ C # \ PrintZPL folder.

This is how its main form looks like:

 

First, you select a report template, then set the export options and select the printer to print. It should be a printer that supports the ZPL command system - in our case it's a Zebra ZD420 printer.

In the program code, you can see how the export settings are controlled in the ZPL format - properties of the object of the ZplExport class:

Property

Description

ZplExport.Density

Density of print depends on the printer model.

Possible Values:

ZplExport.ZplDensity.d6_dpmm_152_dpi,
ZplExport.ZplDensity.d8_dpmm_203_dpi,
ZplExport.ZplDensity.d12_dpmm_300_dpi,
ZplExport.ZplDensity.d24_dpmm_600_dpi.

ZplExport.CodePage

A command in the ZPL language that defines the character encoding. It is sent to the printer each time before printing the label. By default it contains the string "^ CI28", which corresponds to the UTF-8 encoding.

ZplExport.FontScale

Scaling the font size. The default is 1.

ZplExport.PrinterFont

A string indicating the type of font, defaults to "A".

ZplExport.PrintAsBitmap

Print as a bitmap. The default is set to true.

ZplExport.PrinterInit

A string with a set of commands that will be sent once to the printer before the report is printed. Can be used to set orientation, override fonts, or other printer settings.

ZplExport.PrinterFinish

A string with a set of commands that will be sent once to the printer after the report is printed.

ZplExport.PageInit

A string with a set of commands that will be sent to the printer before printing each label.

Sending to print is done by using the FastReport.Export.Text.TextExportPrint.PrintStream method, which passes the stream with ZPL commands to the printer's print queue.

November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.