Last active
April 25, 2016 16:39
-
-
Save katylava/1bfe092249ee2c1854da756e96d4acf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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