Skip to content

How would I pass PDF data between models in Node? #882

@OctaneInteractive

Description

@OctaneInteractive

Hi!

I'm attempting to move from writeStream = fileOperations.createWriteStream( ... ) to streaming the data between models in Node.

try {
  // Create the PDF.
  pdfDoc.pipe(writeStream)
  pdfDoc.end()
  writeStream.on('finish', function () {
    return resolve(true)
  })
} catch(exception) {
  return reject(exception)
}

While this works, this example doesn't when using pdfBytes.buffer, where I'm told:

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

try {
  // Create the PDF.
  const pdfBytes = await pdfDoc.save()
  let buffer = Buffer.from(pdfBytes, 'binary')
  return resolve(buffer)
} catch(exception) {
  return reject(exception)
}

Here I'm told:

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of PDFDocument

The PDF files I'm creating are trivial — less than 10 kilobytes — and it's pointless saving them to disk when it should be possible to pass them between methods.

Any idea how I get at the data in the pdfBytes constant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions