代码之家  ›  专栏  ›  技术社区  ›  jonah13

NodeJS,我们可以使用phantomJs 2和jsreport呈现快捷方式吗

  •  0
  • jonah13  · 技术社区  · 6 年前

    我正在尝试使用jsreport在mac上使用节点js生成pdf,我在jsreport网站上找到了此资源( https://jsreport.net/learn/phantom-pdf#phantomjs2 ),但我不确定如何使用jsreport呈现快捷方式对其进行准确配置(就像下面的代码中使用的那样)

    var http = require('http');
    var jsreport = require('jsreport');
    
    http.createServer(function (req, res) {
    
      jsreport.render("<h1>Hello world</h1>").then(function(out) {
        out.stream.pipe(res);
      }).catch(function(e) {    
        res.end(e.message);
      });
    
    }).listen(1337, '127.0.0.1');
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   BJR Matos    6 年前

    是的,您只需要在请求选项中指定完整的phantomjs版本。

    jsreport.render({
       template: {
           content: '<h1>Hello world</h1>',
           engine: 'none', // replace this with the engine that you are using
           recipe: 'phantom-pdf',
           phantom: {
             phantomjsVersion: '2.1.1' // replace this with the exact version of phantom@2 that you have installed.
           }
        }
    })