0

我尝试了下面的代码来做到这一点......但它不工作......

<!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>
4

1 回答 1

0

页面加载后应立即调用函数“Downloadify”。尝试使用“body onload”方法调用它,例如。或将其包裹在“window.onload()”函数周围

于 2014-04-10T14:03:01.107 回答