UNPKG

zpl-js-helper

Version:

A package that is intended to help with the creation of ZPL labels and templates using JS, with scalable text sizes to prevent overflow and overlap of text.

62 lines (53 loc) 2.31 kB
import { Template, Size, Padding, Origin, TextSection, LabelBuilder } from "../dist/index.cjs"; // Create a new Template instance const template = new Template(50, 100); // Create a new Size instance const upperSize = new Size(50, 400); const productsSize = new Size(250, 800); const padding = new Padding(20, 20, 20, 20); const upperPadding = new Padding(20, 20, 10, 10); // Create an array to store the ZPL sections const sections = []; sections.push(new TextSection('0', new Size(60, 400), new Origin(0, 0), 'class', null, 2, new Padding(20, 20, 10, 0), 'landscape', "R", 50)); sections.push(new TextSection('C', new Size(30, 400), new Origin(60, 0), 'orderNumber', null, 2, upperPadding, 'landscape', "R")); sections.push(new TextSection('C', upperSize, new Origin(90, 0), 'breakName', null, 2, upperPadding, 'landscape', "R", 20)); sections.push(new TextSection('C', new Size(30, 400), new Origin(0, 400), 'orderDate', null, 2, upperPadding, 'landscape')); sections.push(new TextSection('0', new Size(60, 400), new Origin(35, 400), 'name', null, 2, new Padding(20, 20, 0, 0), 'landscape', 'L', 50)); sections.push(new TextSection('A', new Size(60, 400), new Origin(95, 400), 'comment', null, 2, new Padding(20, 20, 0, 0), 'landscape', 'L', 30)); sections.push( new TextSection( "0", productsSize, new Origin(150, 0), "products", "left", 3, padding, "landscape", "L", 40 ) ); // Add all sections to the template sections.forEach((section) => { template.addZPLSection(section); }); const sectionRecords = [ { name: ["JS R Lilly"], class: ["Year 5"], orderDate: ["20 March 2025"], breakName: ["Afternoon tea"], comment: ["Comm: Have a good day.", "ALLG: None"], orderNumber: ["#123213455"], products: [ "1 x Bluetooth Speaker Bluetooth", "2 x 2GB USB (RED) This may also cause some issues", "4 x Wireless Keyboard Let us push this to the", ], }, ]; // Create the LabelBuilder and generate the ZPL const labelBuilder = new LabelBuilder(template, sectionRecords); const zplOutput = labelBuilder.generateZPL(); console.log(zplOutput);