我是Node.js的新手。我正在生成pdf
文件,但是在生成pdf
文件之后缺少内容。在cmd
上以加密形式显示一些数据。
这是代码:
var fs = require('fs');
const jsreport = require('jsreport-core')()
jsreport.init().then(() => {
var something = jsreport.render({
template: {
content: ' This is content ..LBABABABAB',
engine: 'handlebars',
recipe: 'chrome-pdf',
binary : true
},
data: {
foo: "world"
}
}).then((resp) => {
// prints pdf with headline Hello world
//console.log();
var data = resp.content.toString();
console.log(data);
// Write Data to File
fs.writeFile("D:/test.pdf", data, function(err)
{
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
答案 0 :(得分:0)
if we pass the resp.content buffer directly to the writeFile it will work..
like
fs.writeFile("D:/test.pdf", resp.content, function(err)
var fs = require('fs');
const jsreport = require('jsreport-core')()
jsreport.init().then(() => {
var something = jsreport.render({
template: {
content: ' This is content ..LBABABABAB',
engine: 'handlebars',
recipe: 'chrome-pdf',
binary : true
},
data: {
foo: "world"
}
}).then((resp) => {
// prints pdf with headline Hello world
//console.log();
var data = resp.content.toString();
console.log(data);
// Write Data to File
fs.writeFile("D:/test.pdf", resp.content, function(err)
{
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});