Home > front end >  Can I change the default path folder when generate pdf using pdfkit?
Can I change the default path folder when generate pdf using pdfkit?

Time:11-19

I have done generate PDF using pdfkit in node js, but the pdf is downloaded in the default folder download in my computer. Can I change the path of folder from node js, not from setting in my computer?

If needed this is my code

this.downloadPdf = function(req, res, next) {
const PDFDocument = require('pdfkit');
const fs = require('fs');
const blobStream = require('blob-stream');

let pdfDoc = new PDFDocument;
const stream = pdfDoc.pipe(blobStream());
var pdfname = 'SPK';
res.setHeader('Content-disposition', 'inline; filename='  pdfname  '.pdf');

generateHeader(pdfDoc, address, telp_branch, fax)

pdfDoc.fontSize(10)
.text("Data Pembeli", 15, 100)

pdfDoc.fontSize(10)
.text("Detail Pembelian", 15, 281)

displayImage(pdfDoc, ttd_sales, ttd_cust);

pdfDoc.pipe(res);

pdfDoc.end();
};

Using the code above, the downloaded pdf automatically goes to the download folder, i want to change the folder using the node js code. Thankyou very much for all the help ^^

CodePudding user response:

You can do so like this

doc.pipe(fs.createWriteStream('/path/to/file.pdf')); // write to PDF

For further information check this docs: http://pdfkit.org/docs/getting_started.html

  • Related