Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda