I used ChatGPT to help me create a more dynamic version of the ZPL Viewer widget so I could specify DPI and label size in the app.
The only problem is it doesn’t look like there’s a way to dynamically size the widget unless there’s a variable I can set in JS?
// Get values from the user input
let labelResolution = getValue("Label Resolution"); // Could be in DPI or dpmm
let labelWidth = getValue("Label Width"); // In inches
let labelHeight = getValue("Label Height"); // In inches
// Simple check: if resolution >= 100, it's assumed to be DPI, otherwise it's dpmm
if (labelResolution >= 100) {
labelResolution = Math.round(labelResolution / 25.4) + "dpmm"; // Convert DPI to dpmm and round to nearest whole number
} else {
labelResolution = labelResolution + "dpmm"; // Already in dpmm
}
// Construct the dynamic URL
const labelaryURL = `http://api.labelary.com/v1/printers/${labelResolution}/labels/${labelWidth}x${labelHeight}/0/`;
console.log(labelaryURL);
getValue('ZPL Code', (ZPLcode) => {
if (ZPLcode == null) {
const imgURL = labelaryURL + "^xa^cfa,50^fo100,100^fdEnter ZPL Code^fs^xz";
document.getElementById("zpl_print").src = imgURL;
} else {
const imgURL = labelaryURL + ZPLcode;
document.getElementById("zpl_print").src = imgURL;
}
});