Skip to content

Instantly share code, notes, and snippets.

@katylava
Last active April 25, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katylava/1bfe092249ee2c1854da756e96d4acf3 to your computer and use it in GitHub Desktop.
Save katylava/1bfe092249ee2c1854da756e96d4acf3 to your computer and use it in GitHub Desktop.
// A Node.js example which uses the npm package "request" (https://www.npmjs.com/package/request)
// to send a POST request to convert a ZPL string to a PDF file.
var fs = require('fs');
var request = require('request');
var zpl = "^xa^cfa,50^fo100,100^fdHello World^fs^xz";
var options = {
encoding: null,
formData: { file: zpl },
headers: { 'Accept': 'application/pdf' }, // omit this line to get PNG images back
url: 'http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/'
};
request.post(options, function(err, resp, body) {
if (err) {
return console.log(err);
}
var filename = options.headers && options.headers['Accept'] === 'application/pdf' ? 'label.pdf' : 'label.png';
fs.writeFile(filename, body, function(err) {
if (err) {
console.log(err);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment