PDFKit 的保存按钮?
Save button for PDFKit?
是否可以使用 PDFkit 添加保存按钮以下载 pdf 格式?
file = kit.to_file('/path/to/save/pdf')
我在 Github 上看到了这个,但我不知道按下按钮时该怎么做,下载将在浏览器中启动
谢谢
您必须使用以下 link 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
Above code write document into stream ( memory ), once finish stream put into blobStream and then generate url and show in iframe.
When user click button, redirect to url, so they can download already
是否可以使用 PDFkit 添加保存按钮以下载 pdf 格式?
file = kit.to_file('/path/to/save/pdf')
我在 Github 上看到了这个,但我不知道按下按钮时该怎么做,下载将在浏览器中启动
谢谢
您必须使用以下 link 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
Above code write document into stream ( memory ), once finish stream put into blobStream and then generate url and show in iframe.
When user click button, redirect to url, so they can download already