簡體   English   中英

jsreport-core:將標頭與phantom-pdf receipe一起使用

[英]jsreport-core: using header with phantom-pdf receipe

我有一個基於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
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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM