Search code examples
node.jsexpresshttpresponsepdfkit

how to convert pdf array buffer to pdf file using nodejs


Following is the pdf buffer. I want convert buffer to pdf file.

data = {
    "file": {
        "type": "Buffer",
        "data": [
            102,
            24,
            62
        ]
    },
}
res.send( data );

Solution

  • You can use res.sendFile and use the header to send some data along.

    // res.sendFile(path [, options] [, fn])
    
    let options = {
      headers: {
          'TheDataYouWantToSend': Date.now() // for example a timestamp
      }
    }
    
    req.sendFile(absolutePathToFile, options)
    
    

    I hope this helps