javascript jsPDF 输出 PDF 下载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26181905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jsPDF Output PDF Download
提问by ueen
i'm creating a PDF using jsPDF (https://github.com/MrRio/jsPDF).
It's very basic, but suffices to do the job.
To actually create the befor defined PDF is use
doc.output('datauri');
The Doc's are very poor, i don't know what outputtyps are available and if it matters.
It's very hard to find anything about this on google; jsPDF seems to be not so common as is should be.
It opens the PDF but i want the PDF to start downloading as an file.
I want this dialog to open, that ask if i want to save or open.
I hope anyone understands what i'm trying to do.
Thanks in advanced!!
ueen
我正在使用 jsPDF ( https://github.com/MrRio/jsPDF)创建 PDF 。这是非常基本的,但足以完成这项工作。要实际创建之前定义的 PDF 是使用 doc.output('datauri');
Doc 非常糟糕,我不知道有哪些输出类型可用以及它是否重要。在谷歌上很难找到任何关于此的信息;jsPDF 似乎并不像应该的那么常见。它会打开 PDF,但我希望 PDF 开始作为文件下载。我想打开这个对话框,询问我是要保存还是打开。我希望任何人都明白我在做什么。先谢谢了!!温
UPDATE: I found a list of all outputtypes: https://stackoverflow.com/a/18098815/3123142What i want is: doc.output('save', 'filename.pdf'); But it throws an erroralert: "Error in function jsPDF/output: saveAs is not defined" How to fix this?
更新:我找到了所有输出类型的列表:https://stackoverflow.com/a/18098815/3123142 我想要的是:doc.output('save', 'filename.pdf'); 但它会抛出一个错误警报:“函数 jsPDF/输出中的错误:saveAs 未定义”如何解决这个问题?
回答by ueen
Fixed it my own: In my zip of jsPDF wans't a working FileSaver.js so i downloaded it again from github https://github.com/eligrey/FileSaver.jsand linked it in the head, now everything works just fine.
我自己修复了它:在我的 jsPDF zip 中没有一个有效的 FileSaver.js 所以我从 github https://github.com/eligrey/FileSaver.js再次下载它并将它链接到头部,现在一切正常.