javascript - jsreport-core: using header with phantom-pdf receipe -
i've jsreport-core based app, content template renderd fine, header not renderd. here the basic steps in app:
import jsreportcore 'jsreport-core'; import jsreportfsstore 'jsreport-fs-store'; import jsreporttemplates 'jsreport-templates'; import jsreportjsrender 'jsreport-jsrender'; import jsreportphantompdf 'jsreport-phantom-pdf'; import jsreportexpress '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 template directory structure content templated loaded from. (same jsreport-studio).
---- data ------ templates -------- foo ---------- content.html ---------- header.html
solution: put header information in object "phantom" in 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"} } , put parameter in 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
Comments
Post a Comment