JavaScript
JavaScript examples for rendering labels
Multi-page label → PDF with all pages
const apiKey = 'your_api_key_here';
const zpl = '^XA^FO50,50^FDPage 1^FS^XZ^XA^FO50,50^FDPage 2^FS^XZ';
fetch('https://api.zpl.tools/compatibility/labelary/v1/printers/8dpmm/labels/4x6', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Accept': 'application/pdf',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: zpl,
})
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'all-pages.pdf';
a.click();
});Multi-page label → PDF with first page only
const apiKey = 'your_api_key_here';
const zpl = '^XA^FO50,50^FDPage 1^FS^XZ^XA^FO50,50^FDPage 2^FS^XZ';
fetch('https://api.zpl.tools/compatibility/labelary/v1/printers/8dpmm/labels/4x6/0', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Accept': 'application/pdf',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: zpl,
})
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'first-page.pdf';
a.click();
});Multi-page label → PNG with first page only
const apiKey = 'your_api_key_here';
const zpl = '^XA^FO50,50^FDPage 1^FS^XZ^XA^FO50,50^FDPage 2^FS^XZ';
fetch('https://api.zpl.tools/compatibility/labelary/v1/printers/8dpmm/labels/4x6/0', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Accept': 'image/png',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: zpl,
})
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = url;
document.body.appendChild(img);
});