【发布时间】:2020-08-07 15:42:01
【问题描述】:
我正在尝试将 pdfkit 生成的 pdf 文件作为输入发送到 pdflib 以进行合并。我正在使用异步功能。我的项目正在使用sails Js版本开发:“^1.2.3”,“node”:“^12.16”,我的pdf-kit版本是:“^0.11.0”,“pdf-lib”:“^1.9。 0", 这是代码:
const textbytes=fs.readFileSync(textfile);
var bytes1 = new Uint8Array(textbytes);
const textdoc = await PDFDocumentFactory.load(bytes1)
我得到的错误是:
UnhandledPromiseRejectionWarning:错误:无法解析 PDF 文档(行:0 col:0 offset=0):未找到 PDF 标头
请帮我解决这个问题。
【问题讨论】:
-
你可以尝试使用
new ArrayBuffer(textbytes)代替
标签: node.js sails.js pdfkit pdflib node-pdfkit