下面是将图像从本地文件夹写入 pdf 的代码。执行后我不明白为什么会出现以下错误。在 pdf 中没有任何内容打印
doc.pipe(fs.createWriteStream("pdfTemp/" + name_file + ".pdf"));
// callback();
// PDF Creation logic goes here
doc.fontSize(15).text('Wally Gator !', 50, 50);
console.log("inside PDF3");
// Set the paragraph width and align direction
doc.text('www.', {
width: 410,
align: 'left'
});
var newVAr = "newTemp/" + name_file + ".png";
console.log("inside PDF");
doc.image(newVAr, 325, 214, {
fit: [200, 200]
})
.stroke();
console.log("inside PDF2");
callback();
doc.end();
执行上述代码后,PDF 正在生成,但出现以下错误。
Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:156:17)
at PDFDocument.Readable.push (_stream_readable.js:134:10)
at PDFDocument._write (R:\pdftest\node_modules\pdfkit\js\document.js:156:12)
at PDFReference.finalize (R:\pdftest\node_modules\pdfkit\js\reference.js:81:21)
at PDFReference.finalize (R:\pdftest\node_modules\pdfkit\js\reference.js:10:59)
at PDFReference.end (R:\pdftest\node_modules\pdfkit\js\reference.js:74:21)
at PNGImage.finalize (R:\pdftest\node_modules\pdfkit\js\image\png.js:83:15)
at R:\pdftest\node_modules\pdfkit\js\image\png.js:114:28
at Deflate.onEnd (zlib.js:227:5)
at emitNone (events.js:91:20)
doc = new PDF();
doc.pipe(fs.createWriteStream("pdfTemp/" + name_file + ".pdf"));
// callback();
// PDF Creation logic goes here
doc.fontSize(15).text('Wally Gator !', 50, 50);
console.log("inside PDF3");
// Set the paragraph width and align direction
doc.text('www.', {
width: 410,
align: 'left'
});
var newVAr = "newTemp/" + name_file + ".png";
console.log("inside PDF");
doc.image(newVAr, 325, 214, {
fit: [200, 200]
})
.stroke();
console.log("inside PDF2");
callback();
doc.end();
需要声明 doc = new PDF();循环内
我是一名优秀的程序员,十分优秀!