zplify
v1.0.0
Published
Generate a table in ZPL format based on a simple set of inputs
Downloads
12
Maintainers
Readme
ZPLify
Background
The ZPL language is used to pass data to Zebra thermal printers, which are commonly used to print receipts. In the case of this module, the principle focus is printing a food label based on a set of input data.
Install
In terminal, in the same directory as your node_modules
directory:
npm install zplify --save
In your module:
(function() {
const zplify = require('zplify');
// your code here
})();
Usage
The main method to be used is generateTable
, which takes an object with 2 properties:
rows
- a matrix (array of arrays), in which each entry corresponds to a table rowconfig
- an object containing properties for modifying the default formatting
It is assumed that the first item in the rows
array will an array of column titles,
which receive slightly different styling than the rest of the rows.
Example:
zplify.generateTable({
rows: [
['col1', 'col2'],
['row1col1', 'row1col2']
],
config: {
columnRatios: [.3, .7]
}
});
// returns a table with 2 rows and 2 columns, where row contains the column names
Config parameters
columnRatios
type:
Array
default:
[]
(evaluates to evenly spaced columns)description: specifiy custom widths for the table columns
notes:
- must contain an equal number of items as the
columns
array - entries must add up to 1
- each entry must be greater than 0 and less than 1
- must contain an equal number of items as the
example:
zplify.generateTable({ rows: [ ['id', 'name', 'qty', 'price'], ['1', 'Delicious Dog Food', '2', '42'] ], config: { columnRatios: [.1, .7, .1, .1] // same number of values as the first row } });
labelWidth
type:
Number
unit:
inches
default:
4
descripton: specify the total width of the label
notes:
- width must be greater than 0
labelHeight
type:
Number
unit:
inches
default:
6
description: specify the total height of the label
notes:
- height must be greater than 0
printDensity
- type:
Number
- unit:
DPI
(dots per inch) - default:
203
(8 dpmm) - description: specify the dot resolution of the print
- type:
labelPadding
- type:
Number
- unit:
dots
- default:
50
- description: specify the amount of space you'd like around the table
- type:
borderWidth
- type:
Number
- unit:
dots
- default:
3
- description: specify how thick youd like the lines on the table to be
- type:
fontSize
- type:
Number
- unit:
dots
- default:
30
- description: specify how big you'd like the font to be
- type:
maxRowHeight
- type:
Number
- unit:
dots
- default: twice the
fontSize
(so,60
dots; see above) - description: specify the maximum height you'd like a row to be
- type:
rowHeight
- type:
Number
- unit:
dots
- default: equal to the
maxRowHeight
(so,60
dots; see above) - description: specify the height that you'd like each row to be
- type:
cellPadding
- type:
Number
- unit:
dots
- default:
20
- description: specify the amount of space you'd like to the left of each cell value
- notes:
- this does not apply to cells that have been horizontally centered
- type:
Testing
To see how the table you generated looks, you can use Labelary.
A bit about the logic
ZPL II is not backwards compatable with ZPL I [1], which is to say that an interpreter expecting ZPL II code will not necessarily return the correct results given an input in the ZPL I format. As such, I've elected to use the more recent version, ZPL II.
I may choose to add more features in following versions. If you'd like to request a feature, please reach out to [email protected]. Here are some I'm thinking might be useful:
- configuration option to produce output in the ZPL I format.
- overflow detection for a cell & handling protocol (wrap, throw error, or custom handler)
Resources
Learn more about the Zebra programming language here: