[英]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.