【问题标题】:How to enable downloadify in jsPdf?如何在 jsPdf 中启用 downloadify?
【发布时间】:2015-07-24 12:29:16
【问题描述】:

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

【问题讨论】:

    标签: jspdf html-to-pdf downloadify


    【解决方案1】:

    这些是步骤,但是对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 中添加 &lt;div id="downloadify"&gt;。这个 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.
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-22
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 2017-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多