首页 > 解决方案 > 如何使用nodejs将pdf数组缓冲区转换为pdf文件

问题描述

以下是 pdf 缓冲区。我想将缓冲区转换为 pdf 文件。

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

标签: node.jsexpresshttpresponsepdfkit

解决方案


您可以使用res.sendFile并使用标头发送一些数据。

// res.sendFile(path [, options] [, fn])

let options = {
  headers: {
      'TheDataYouWantToSend': Date.now() // for example a timestamp
  }
}

req.sendFile(absolutePathToFile, options)

我希望这有帮助


推荐阅读