是否可以使用PDFkit添加一个用于下载pdf的保存按钮?
ProductBase
我在Github上看到了这个,但我不知道按下按钮时该怎么做,下载将在浏览器中启动
谢谢你
答案 0 :(得分:1)
您必须使用以下链接https://github.com/devongovett/pdfkit
# require dependencies
PDFDocument = require 'pdfkit'
blobStream = require 'blob-stream'
# create a document the same way as above
doc = new PDFDocument
# pipe the document to a blob
stream = doc.pipe(blobStream())
# add your content to the document here, as usual
# get a blob when you're done
doc.end()
stream.on 'finish', ->
# get a blob you can do whatever you like with
blob = stream.toBlob('application/pdf')
# or get a blob URL for display in the browser
url = stream.toBlobURL('application/pdf')
iframe.src = url
上面的代码将文档写入流(内存),一旦完成流放入blobStream然后生成url并在iframe中显示。
当用户点击按钮时,重定向到网址,以便他们可以下载