Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to send PDF to stream

I try to generate a mail with a PDF attachment. How do I write the PDF directly to attachment? I tried this one:

var pdf = printer.createPdfKitDocument(docDefinition);
const content = new stream.Writable();
pdf.pipe(content);
pdf.end();

let mail = await transporter.sendMail({
   from: sender,
   to: recipient,
   subject: "Subject of Mail",
   text: "Here is the latest Overview",
   attachments: [{ filename: 'Overview.pdf', contentType: 'application/pdf', content: content }]
});

node:internal/streams/writable:589
    throw new ERR_METHOD_NOT_IMPLEMENTED('_write()');
    ^
Error [ERR_METHOD_NOT_IMPLEMENTED]: The _write() method is not implemented
    at new NodeError (node:internal/errors:371:5)
    at Writable._write (node:internal/streams/writable:589:11)
    at writeOrBuffer (node:internal/streams/writable:390:12)
    at _write (node:internal/streams/writable:331:10)
    at Writable.write (node:internal/streams/writable:335:10)
    at PDFDocument.ondata (node:internal/streams/readable:777:22)
    at PDFDocument.emit (node:events:390:28)
    at PDFDocument.Readable.read (node:internal/streams/readable:550:10)
    at flow (node:internal/streams/readable:1035:34)
    at resume_ (node:internal/streams/readable:1016:3) {
  code: 'ERR_METHOD_NOT_IMPLEMENTED'
}

It works fine when I safe the PDF to a temporary file, but I like to avoid that:

let filePath = tmp.tmpNameSync({ postfix: ".pdf" });
var pdf = printer.createPdfKitDocument(docDefinition);
pdf.pipe(fs.createWriteStream(filePath));
pdf.end();

let mail = await transporter.sendMail({
   ...
   attachments: [{ filename: 'Overview.pdf', path: filePath }]
});
fs.unlink(filePath,
   err => { if (err) logger.error(err) }
);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!