Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在nodejs中使用pdfkit来创建pdf。现在,要从 pdfDocument 中获取数据,我首先使用“fs”将其写入文件,然后从其中读取。
我希望能够直接使用来自 pdfDocument 对象的数据并将其作为响应发送。我怎样才能做到这一点?
每个 pdfDocument 都是一个流。您基本上可以将其通过管道传递给这样的响应:
require('http').createserver(function (request, response) { var pdfdocument = require('pdfkit'), pdfdocument = new pdfdocument(); pdfdocument.text('wassup'); pdfdocument.pipe(response); pdfdocument.end() }).listen(1999);