Javascript jspdf-保存pdf
我是Javascript新手。 我想使用jspdf.js使用javascript打印 我有这个密码Javascript jspdf-保存pdf,javascript,html,pdf,jspdf,Javascript,Html,Pdf,Jspdf,我是Javascript新手。 我想使用jspdf.js使用javascript打印 我有这个密码 <!doctype> <html> <head> <title>Generate PDF</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/
<!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>
生成PDF
函数下载PDF(){
Downloadify.create('Downloadify'{
文件名:“Simple.pdf”,
数据:函数()
{
var doc=new jsPDF();
文件setFontSize(22);
doc.text(20,20,“我的第一个PDF”);
doc.addPage();
文件setFontSize(16);
doc.text(20,30,'下面是一些正常大小的文本');
返回单据输出();
},
onComplete:function(){alert('您的文件已保存!');},
onCancel:function(){alert('您已取消保存此文件');},
onError:function(){alert('您必须在文件内容中放入某些内容,否则将无法保存!');},
downloadImage:'images/download.png',
swf:'images/downloadify.swf',
宽度:100,
身高:30,
透明:是的,
附加:false
});
}
要生成PDF,请单击此处。
但它不起作用。我需要做什么吗?谢谢
请帮帮我。。提前感谢。downloadify插件旨在构建一个按钮,供您在页面运行时单击,因此将其设置为运行downloadify脚本onclick是行不通的,请添加此插件并删除您制作的按钮:
<body onload="downloadPDF()">
我唯一的其他建议是使用dist文件夹中的jspdf.min.js,而不仅仅是标准的jspdf.js文件。min文件夹包含构建PDF所需的所有插件/函数。继续包括downloadify和swfobject,但它们不包括在最小构建包中
注意:我仍在试图弄清楚如何让downloadify自己添加实际的页面内容,文档非常糟糕。当我输入代码来执行此操作时,当我单击Save to Disk(保存到磁盘)按钮时,实际上什么都没有发生,没有控制台错误,没有下载发生,什么都没有
另外,你说你想用jsPDF打印……但是jsPDF和downloadify所做的就是将你的页面转换成PDF文件下载,而不是打印 在您的浏览器中是否工作?