繁体   English   中英

jspdf-保存pdf

[英]jspdf - saving a pdf

我是Java语言的新手。 而且我想使用jspdf.js使用javascript打印。

我有这个代码。

    <!doctype>
<html>
<head>
    <title>Generate PDF</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />   
    <script type="text/javascript" src="js/libs/swfobject.js"></script>
    <script type="text/javascript" src="js/libs/downloadify.min.js"></script>
    <script type="text/javascript" src="js/jspdf/jspdf.js"></script>
    <script type="text/javascript">


    function downloadPdf(){

        Downloadify.create('downloadify',{
            filename: 'Simple.pdf',
            data: function()
            { 
                    var doc = new jsPDF();
                    doc.setFontSize(22);
                    doc.text(20, 20, 'My First PDF');
                    doc.addPage();
                    doc.setFontSize(16);
                    doc.text(20, 30, 'This is some normal sized text underneath.'); 
                return doc.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!'); },
            downloadImage: 'images/download.png',
            swf: 'images/downloadify.swf',
            width: 100,
            height: 30,
            transparent: true,
            append: false
        });
    }
</script>   
<body>
To generate PDF Click Here.
<input type="button" value="Generate" onclick="downloadPdf()" />
<br/>
<div id="downloadify"></div>

但这是行不通的。 我需要做什么吗? 谢谢! 请帮助我..在此先感谢。

downloadify插件旨在构建供您在页面运行时单击的按钮,因此将其设置为运行downloadify脚本onclick不会起作用,而是添加它并摆脱您所做的按钮:

<body onload="downloadPDF()">

我唯一的其他建议是使用dist文件夹中的jspdf.min.js而不是仅使用标准jspdf.js文件。 min文件夹包含构建PDF所需的所有插件/功能。 尽管继续包括downloadify和swfobject,但它们不包含在该min build软件包中。

注意:我仍在尝试自己如何获取downloadify来添加实际的页面内容,该文档非常糟糕。 当我放入代码时,单击“保存到磁盘”按钮几乎没有任何反应,没有控制台错误,没有下载,也没有任何反应。

另外,您说过要使用jsPDF进行打印...但是所有jsPDF和downloadify都可以将页面转换为PDF文件进行下载, 而不是打印。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM