Client for Node.js to use pdfmiweb API service. For more informacion go to http://pdfmiweb.com/api
##Usage:
npm install pdfmiweb-pdf-client
var pdfmiwebPdfClient = require('pdfmiweb-pdf-client').PDF;
var PDF = new pdfmiwebPdfClient("http://api.pdfmiweb.com", "[[YOUR APPID]]", "[[YOUR APIKEY]]")
To get an APPID and APIKEY go to http://usuarios.pdfmiweb.com
###Creating PDFs
Only creates PDFs in API server. for get it use PDF.get()
.
var params = {
webPage: "http://yourwebpage.com/articles?id=20",
paperSize: "A3", //optional, defaults A4
orientation: "landscape", //optional defaults "portrait"
paperMargins: "1cm", //optional defaults "0cm"
};
PDF.create(params, function (err, res) {
if (res.body.status) {
console.log("API says PDF has been created :)");
} else {
console.log("API says PDF has not been created :(");
}
});
###Getting PDFs (and optionally storing locally)
var params = {
webPage: "http://yourwebpage.com/articles?id=20",
paperSize: "A3", //optional, defaults A4
orientation: "landscape", //optional defaults "portrait"
paperMargins: "1cm", //optional defaults "0cm"
};
//You can get a PDF as stream and do what you want:
PDF.get(params, function (res, pdfStream) {
if (res.statusCode == 200) {
console.log("pdfStream contains the PDF. You can use PDF.save() to store locally or Express's res.download() to sent to browser.");
} else if (res.statusCode == 404) {
console.log("PDF does not exist, you should create before using PDF.create()");
} else {
console.log("oops!");
}
});
//Or use in tandem with `PDF.save()` to store locally:
PDF.get(params, function (res, pdfStream) {
PDF.save(pdfStream, "path/to/save/a-name-for-this.pdf", function (err, filepath) {
if (err) throw err;
//And maybe sent to user
res.download(filepath);
});
});