paper.js/examples/Node.js/JSONtoPDF.js
2016-01-27 09:34:37 +01:00

18 lines
513 B
JavaScript

var paper = require('paper'),
path = require('path'),
fs = require('fs');
var canvas = paper.createCanvas(612, 792, 'pdf');
paper.setup(canvas);
fs.readFile('./in.json', { encoding: 'utf8' }, function (err, data) {
if (err)
throw err;
paper.project.importJSON(data);
paper.view.update();
fs.writeFile(path.resolve(__dirname, 'out.pdf'), canvas.toBuffer(), function (err) {
if (err)
throw err;
console.log('Saved!');
process.exit();
});
});