我写了这个简单的代码来测试 jsPDF
库:
const base64Img = require('base64-img');
const JsPDF = require('jspdf');
const LAYOUT = base64Img.base64Sync('img/layout.png');
$('#esporta').click( () => {
var pdf = new JsPDF();
pdf.addImage(LAYOUT, 'PNG', 18.25, 19.25, 190, 255);
pdf.save('test.pdf');
});
我有一个简单的按钮,当它被点击时应该生成pdf;但我遇到了这个错误:
Uncaught TypeError: Cannot read property 'charAt' of undefined at new e (/Users/th3g3ntl3man/Repository/thermowell-design/node_modules/jspdf/dist/jspdf.min.js:269) at HTMLButtonElement.$.click (export.js:62) at HTMLButtonElement.dispatch (jquery-3.3.1.min.js:2) at HTMLButtonElement.y.handle (jquery-3.3.1.min.js:2)
export.js:62
行是创建pdf的地方:var pdf = new JsPDF();