2016-05-26 10 views
1

PDFkitでダウンロードするための保存ボタンを追加することはできますか?PDFKitの保存ボタン?

file = kit.to_file('/path/to/save/pdf') 

私はGithubの上でこれを見ましたが、私はボタンを押すと、ダウンロードがブラウザにあなたが

答えて

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に表示します。

ユーザーのクリックボタンは、URLにリダイレクトするので、彼らは

+0

おかげに、すでにあなたをダウンロードすることができますが、私は「doc.end()」ボタンをクリックして上のイベントを取得するために何を交換する必要がありますか? – Hightline

+0

ボタンイベントestiddeadを 'finish'にする方法は? – Hightline

+0

pdfが作成されたばかりで、button.src = urlを入れてください。上記のコードはCoffeeScriptにあり、blob-streamはnodejsモジュールです – Goddard

関連する問題