Search code examples
node.jsexpresspdfbackend

convert pdf Binary data into a viewable pdf


I made a request from my express js back-end server to an external server for a pdf file and this is the response I get.

response{

'%PDF-1.5\n' +
    '%����\n' +
    '3 0 obj\n' +
    '<</ColorSpace/DeviceRGB/Subtype/Image/Height 224/Filter......'

}

I am assuming that this is the binary data of that pdf if so then is there a way to convert and process this data in my express js server into a viewable pdf file. please help.


Solution

  • I'm absurdly late, but here you go:

    res.status(200).header({ "Content-Type": "application/pdf" }).send(pdf);
    //         ^             ^tells the browser that the
    //         success        binary is a pdf
    

    Hope this helps! (Either you, or someone else)