gpt4 book ai didi

node.js - 如何将本地镜像写入PDFkit?

转载 作者:太空宇宙 更新时间:2023-11-03 22:08:27 26 4
gpt4 key购买 nike

下面是将图像从本地文件夹写入 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();循环内

关于node.js - 如何将本地镜像写入PDFkit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49400540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com