Reputation: 561
I've a jsreport-core based app, the content template is renderd fine, but the header is not renderd. Here the the basic steps in my app:
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);
});
This is the template directory structure where the content templated is loaded from. (Same as from jsreport-studio).
---- data
------ templates
-------- foo
---------- content.html
---------- header.html
Upvotes: 0
Views: 1149
Reputation: 561
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
Upvotes: 1