You can actually use jspdf directly (npm install jspdf
instead of npm install node-jspdf
). Jspdf is currently (v1.3.2) not built with node support in mind, but you can mock the globals like below and get it to work that way. This is a basic example and all features of jspdf will not be available.
global.window = {document: {createElementNS: () => {return {}} }};
global.navigator = {};
global.html2pdf = {};
global.btoa = () => {};
var fs = require('fs');
var jsPDF = require('jspdf');
var doc = new jsPDF();
doc.text("Hello", 10, 10);
var data = doc.output();
fs.writeFileSync('./document.pdf', data, 'binary');
delete global.window;
delete global.html2pdf;
delete global.navigator;
delete global.btoa;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…