嘿,我已将 jsPdf 添加到我的 HTML 中以将 HTML 下载为 PDF,但在 IE 9 中它不起作用。它没有下载任何PDF,所以我搜索了这个并得到了我必须为此启用IE shim,所以你能帮我看看我怎么能做到这一点,我试过使用Downloadify但不明白如何传递完整的 HTML 文件并将其图像转换为 PDF。
问问题
3453 次
1 回答
0
这些是步骤,但是对downloadify的支持很差。
<script src="./js/jspdf/libs/Downloadify/js/downloadify.min.js"></script>
<script src="./js/jspdf/libs/Downloadify/js/swfobject.js"></script>
将这些脚本标签添加到页面顶部(根据 jspdf 的 lib 目录中的文件更改路径):
<div id="downloadify">
在您的 dom. 这个 div 应该是空的。
接下来,在页面底部添加一个脚本标记,该标记将在填充 DOM 后运行。此脚本将在“#downloadify”div 中生成一个按钮。把它放在脚本标签里面:
Downloadify.create('downloadify',{ // this first argument id a dom element id. this is how it knows where to populate the flash button it's creating.
filename: "afilename.pdf",
data: function(){
// generate your pdf here.
var pdf = new jsPDF;
// various other jspdf commands here
return pdf.output();
},
onComplete: function(){
alert('Your File Has Been Saved!');
},
onCancel: function(){
alert('You have cancelled the saving of this file.');
},
onError: function(){
alert('You must put something in the File Contents or there will be nothing to save!');
},
swf: './js/jspdf/libs/Downloadify/media/downloadify.swf', // make sure this links properly to your file as well.
downloadImage: './js/jspdf/libs/Downloadify/images/download.png', // this is the link to the image of the button itself. An ugly default is included. If you want to style the button, you have to create a sprite image of the same kind.
width: 100, // width of the button
height: 30, // 1/4 height of the button image (which has four states present)
transparent: true, // seems to do nothing, set to true or false.
append: false // have not figured out what this does.
});
于 2016-02-03T20:13:34.427 回答