如何在jsPdf中启用downloadify?

时间:2015-07-24 12:29:16

标签: jspdf html-to-pdf downloadify

嘿我已将jsPdf添加到我的HTML中以将PDF下载为HTML,但在IE 9中它不起作用。它没有下载任何PDF所以我搜索了这个并得到了我必须为此启用IE垫片所以你能帮我解决我怎么能够做到这一点,我试图使用Downloadify但是不明白如何传递完整的HTML文件并将其转换为PDF格式。

1 个答案:

答案 0 :(得分:0)

这些是步骤,但对downloadify的支持很差。

将这些脚本标记添加到页面顶部(根据jspdf的lib目录中的文件更改路径): <script src="./js/jspdf/libs/Downloadify/js/downloadify.min.js"></script> <script src="./js/jspdf/libs/Downloadify/js/swfobject.js"></script> 在你的dom中添加<div id="downloadify">。这个div应该是空的。

接下来,在页面底部添加一个脚本标记,该标记将在填充DOM后运行。该脚本将在'#downifyify'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.
                });