我有一个基于jsreport-core的应用程序,内容模板渲染得很好,但标题没有渲染。这是我的应用程序中的基本步骤:
import jsreportCore from 'jsreport-core';
import jsreportFsStore from 'jsreport-fs-store';
import jsreportTemplates from 'jsreport-templates';
import jsreportJsrender from 'jsreport-jsrender';
import jsreportPhantomPdf from 'jsreport-phantom-pdf';
import jsreportExpress from 'jsreport-express';
// ...
jsreport.use(new jsreportFsStore({dataDirectory: "data", syncModifications: true}));
jsreport.use(new jsreportTemplates());
jsreport.use(new jsreportJsrender);
jsreport.use(new jsreportPhantomPdf());
jsreport.use(new jsreportExpress({app : app}));
// ...
const jsreport = new jsreportCore({
loadConfig: false,
autoTempCleanup: true,
connectionString: { 'name': 'fs' },
tasks: { allowedModules: '*' }
});
// ...
jsreport.render({ template : {name: "foo",engine: "jsrender",recipe:"phantom-pdf"},data : dataObj}).then((out) => {
out.stream.pipe(res);
}).catch((e) => {
res.end(e.message);
});
这是模板目录结构,其中加载了模板化内容。 (与jsreport-studio相同)。
---- data
------ templates
-------- foo
---------- content.html
---------- header.html
答案 0 :(得分:1)
Solution: put the header information in a object "phantom" in the render paramter object:
{
template : {name: "foo",engine:"jsrender",recipe:"phantom-pdf",phantom :{
header :"<h1>TEST HEAD <div style='text-align:center'{{#pageNum}}/{{#numPages}}</div> </h1>", headerHeight : "10cm"}
}
and put an extra parameter in the jsreport-phantom-pdf contructor:
jsreport.use(new jsreportPhantomPdf({ strategy: 'phantom-server' }));
ref:
https://github.com/jsreport/jsreport-phantom-pdf
https://www.npmjs.com/package/phantom-pdf
http://jsreport.net/learn/phantom-pdf