Skip to content

Instantly share code, notes, and snippets.

@ryankirkman
Created March 23, 2011 23:24
Show Gist options
  • Save ryankirkman/884248 to your computer and use it in GitHub Desktop.
Save ryankirkman/884248 to your computer and use it in GitHub Desktop.
Trying to make a node.js module to interact with pdfcrowd
var sys = require('sys');
var fs = require('fs');
var restler = require('restler');
exports.generate_pdf = function(username, api_key, src_data, res) {
console.log("starting to generate pdf");
console.log(username);
console.log(api_key);
console.log(src_data);
restler.post('http://pdfcrowd.com/api/pdf/convert/html/', {
data: {
username: username,
key: api_key,
src: src_data
},
}).on('complete', function(data, response) {
console.log("we are complete, but do we have data?");
/* Actually send the data. Hack it so that the
* headers and status code are what pdfcrowd
* responded with.
*/
res.send(data, response.headers, response.statusCode);
}).on('error', function(data, response) {
console.log("ERROR");
fs.writeFile('data.out', sys.inspect(data));
fs.writeFile('response.out', sys.inspect(response));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment