我在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();
}发布于 2021-06-17 08:26:37
const jsreport = require('jsreport-core')()
jsreport.use(require('jsreport-chrome-pdf')())
jsreport.use(require('jsreport-pdf-utils')())
jsreport.use(require('jsreport-handlebars')())
const fs = require('fs').promises
;(async () => {
await jsreport.init()
const response = await jsreport.render({
template: {
content: 'Hello from main report',
engine: 'handlebars',
recipe: 'chrome-pdf',
pdfOperations: [{
type: 'append',
template: {
engine: 'handlebars',
recipe: 'chrome-pdf',
content: 'Content to append'
}
}]
}
})
await fs.writeFile('out.pdf', response.content)
await jsreport.close()
})()我建议检查特定存储库单元测试,总是有很多例子。
https://stackoverflow.com/questions/68003222
复制相似问题