我尝试了下面的代码来做到这一点......但它不工作......
<!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>