从我读到的内容来看,他的应该有效。但它只是下载一个空文档。所以我一定是错误地处理了管道。
如果我将其通过管道传输到
fs.createWriteStream
,效果很好...
import PDFDocument from 'pdfkit'
const downloadPdfRoute = async (app) => {
app.get('/download/:filename', async (req, reply) => {
const doc = new PDFDocument()
reply.type('application/pdf')
reply.header(
'content-disposition',
`attachment; filename="${req.params.filename}"`
)
doc.pipe(reply.raw)
doc.text('Hello, this is your PDF content.')
doc.end()
})
}
export default downloadPdfRoute
我做错了什么?