0

I need to convert a PDF data array type buffer into an ArrayBuffer. here's an example

this.templateService.get(data[0].templateId).subscribe({
          next: async (data) => {
            this.datatemplate = data.datatemplate  


this.datatemplate {type: 'Buffer', data: Array(185251)} // type of data

when i try to read this data using PDF-LIB,

const pdfDoc = await PDFDocument.load(this.datatemplate)
    const form = pdfDoc.getForm()
    const fields = form.getFields()
    fields.forEach(field => {
      const type = field.constructor.name
      const name = field.getName()
      console.log(`${type}: ${name}`)
    })

I've got this error

TypeError: pdf must be of type string or Uint8Array or ArrayBuffer, but was actually of type NaN

any help please?

4
  • where are you initializing the array variable? please show all relevant code Commented Mar 18, 2023 at 1:09
  • As written, its hard to tell what you are passing in, but the error is saying the array variable is set to NaN which definitely is not an array Commented Mar 18, 2023 at 1:16
  • i edited my post. i'm getting PDF data from postgres database. Commented Mar 18, 2023 at 8:36
  • can you show this class/object that this is referring too? Commented Mar 18, 2023 at 14:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.