paper.js/examples/Node.js/JSONtoPDF.js

18 lines
489 B
JavaScript
Raw Normal View History

2013-11-29 06:17:59 -05:00
var paper = require('paper'),
2014-08-16 13:24:54 -04:00
path = require('path'),
fs = require('fs');
2013-11-29 06:17:59 -05:00
var canvas = paper.createCanvas(612, 792, 'pdf');
2013-11-29 06:17:59 -05:00
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) {
2014-08-16 13:24:54 -04:00
if (err)
throw err;
console.log('Saved!');
2014-08-16 13:24:54 -04:00
});
});