将文本附加到现有的PDF File电子node.js
我正在从电子中的选定文本生成pdf文件。但是我想在此pdf文件中添加文字,但每次都会覆盖该文件。是否可以通过任何方式将文本附加到PDF文件的末尾?
win.once('ready-to-show', () => {
win.webContents.printToPDF(pdfSettings(), function(err, data) {
win.close();
if (err) {
//do whatever you want
return;
}
try{
fs.writeFileSync(filename, data);
console.log("save");
}catch(err){
//unable to save pdf..
console.log("unable to save" + err);
}
})
});
回答如下:尝试使用fs.appendFileSync()代替fs.writeFileSync
将文本附加到现有的PDF File电子node.js
我正在从电子中的选定文本生成pdf文件。但是我想在此pdf文件中添加文字,但每次都会覆盖该文件。是否可以通过任何方式将文本附加到PDF文件的末尾?
win.once('ready-to-show', () => {
win.webContents.printToPDF(pdfSettings(), function(err, data) {
win.close();
if (err) {
//do whatever you want
return;
}
try{
fs.writeFileSync(filename, data);
console.log("save");
}catch(err){
//unable to save pdf..
console.log("unable to save" + err);
}
})
});
回答如下:尝试使用fs.appendFileSync()代替fs.writeFileSync