如何在javascript中写入PDF并从服务器下载PDF。。。。。有人能告诉我怎么解决这个问题吗
我尝试了下面的代码来做它。。。但它不起作用如何在javascript中写入PDF并从服务器下载PDF。。。。。有人能告诉我怎么解决这个问题吗,javascript,html,pdf,Javascript,Html,Pdf,我尝试了下面的代码来做它。。。但它不起作用 <!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"
<!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: 'myPDF.pdf',
data: function()
{
var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'Hello World');
doc.addPage();
doc.setFontSize(16);
doc.text(20, 30, 'Second Page 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>
</head>
<body>
To generate PDF Click Here.
<input type="button" value="Generate" onClick="downloadPdf();" />
<br/>
<div id="downloadify"></div>
</body>
</html>
生成PDF
函数下载PDF()
{
Downloadify.create('Downloadify',
{
文件名:“myPDF.pdf”,
数据:函数()
{
var doc=new jsPDF();
文件setFontSize(22);
doc.text(20,20,‘你好世界’);
doc.addPage();
文件setFontSize(16);
文本(20,30,'第二页,下面是一些正常大小的文本');
返回单据输出();
},
onComplete:function(){alert('您的文件已保存!');},
onCancel:function(){alert('您已取消保存此文件');},
onError:function(){alert('您必须在文件内容中放入某些内容,否则将无法保存!');},
downloadImage:'images/download.png',
swf:'images/downloadify.swf',
宽度:100,
身高:30,
透明:是的,
附加:false
});
}
要生成PDF,请单击此处。
加载页面后应立即调用函数“Downloadify”。
尝试使用“body onload”方法调用它
如。
或者将其环绕在“window.onload()”函数中,查看一下(对于Node.js)和/或可能会很有用。我尝试了这两种方法,但找不到代码。。。视差使用服务器中的一些代码。。。pdfkit.org使用其他代码,而不是js。。。。有人能帮我写完整的代码吗。。