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

21 lines
657 B
JavaScript
Raw Permalink Normal View History

// Please note: When loading paper as a normal module installed in node_modules,
// you would use this instead:
// var paper = require('paper-jsdom-canvas');
var paper = require('../../dist/paper-core.js');
var path = require('path');
var 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('./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
});
});