jsreport/jsreport-core

Example with phantom-pdf produces a blank PDF

Closed this issue · 3 comments

jsreport-phantom-pdf always produces an empty PDF, even with the example from the README:

var jsreport = require('jsreport-core')()
var fs = require("fs");
var output_fn = "/vagrant/test.pdf";

jsreport.init().then(function () {
   return jsreport.render({
       template: {
           content: '<h1>Hello {{:foo}}</h1>',
           engine: 'jsrender',
           recipe: 'phantom-pdf'
        },
        data: {
            foo: "world"
        }
    }).then(function(resp) {
        const pdf = resp.content.toString();
        console.log(pdf);
        fs.writeFileSync(output_fn, pdf);
        console.log("Saved PDF content to " + output_fn);
   });
}).catch(function(e) {
    console.log(e)
})

Producing HTML output works fine with handlebars or jsrender, but phantom-pdf always produces the same PDF without any kind of text. Same result with phantomjs-prebuilt and customPhantomJS: true.

PhantomJs version of the standard include:

$ /home/vagrant/node_modules/jsreport-phantom-pdf/node_modules/phantom-html-to-pdf/node_modules/phantom-workers/node_modules/phantomjs/lib/phantom/bin/phantomjs --version
1.9.8

PhantomJs version of phantomjs-prebuilt:

$ /home/vagrant/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs --version
2.1.1

Node module versions:

  • jsreport-core: 0.6.3
  • jsreport-phantom-pdf: 0.4.2
    • phantom-html-to-pdf: 0.4.1
  • phantomjs-prebuilt: 2.1.7

Hi,

this has something to do with encoding problem when you toString buffer and pass it to writeFileSync...

The best answer I can give you right now is to pass the resp.content buffer directly to the writeFilteSync

fs.writeFileSync(output_fn, resp.content);

Thanks, this did the trick! Works 👍

Thanks, this did the trick! Works 👍

Hi mechris I have the same issue, can you show me how your example looks?