【发布时间】:2021-06-17 16:26:37
【问题描述】:
我阅读了https://jsreport.net/learn/pdf-utils,但没有找到在不使用 js 报告工作室时如何通过脚本附加文件的答案。
这是我的代码:
main.js
const jsreport = require('jsreport-core')();
const fs = require('fs');
const d = require('./child');
const foo = async() => {
await jsreport.init();
const resp = await jsreport.render({
template: {
content: '<h1>Hello {{foo}}</h1>',
engine: 'handlebars',
recipe: 'chrome-pdf'
},
data: {
foo: "1"
}
});
fs.writeFileSync('jsreport.pdf', resp.content);
process.exit();
}
foo();
child.js
module.exports = function beforeRender(req, res, done) {
req.template.content = req.template.content('1', '2')
done();
}
【问题讨论】:
标签: jsreport