2013-06-18 4 views
1

나는 자바 스크립트에 새로운이야. 그리고 jspdf.js를 사용하여 자바 스크립트를 사용하여 인쇄하고 싶습니다.jspdf - 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"></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> 

하지만 작동하지 않습니다. 나는 아무것도해야합니까? 감사! 제발 도와주세요 .. 미리 감사드립니다.

+0

브라우저에 [sample jspdf] (http://parall.ax/products/jspdf)가 작동합니까? – Anusha

답변

0

downloadify 플러그인은 페이지 실행시 클릭 할 수있는 버튼을 만들기 때문에 downloadclick 스크립트를 실행하도록 설정하면 onclick이 작동하지 않습니다. 대신이 버튼을 추가하고 작성한 버튼을 제거하십시오 :

<body onload="downloadPDF()"> 

내 유일한 다른 제안은 대신 표준 jspdf.js 파일의 DIST 폴더에있는 jspdf.min.js을 사용하는 것입니다. min 폴더에는 PDF를 작성하는 데 필요한 모든 플러그인/함수가 들어 있습니다. 다운로드 및 swfobject 포함 유지, 그들은 그 최소 빌드 패키지에 포함되지 않습니다.

참고 : 저는 여전히 실제 페이지 콘텐츠를 직접 추가하기 위해 downloadify를 얻는 방법을 알아 내려고 노력하고 있습니다. 설명서는 매우 형편 없습니다. 코드를 입력하면 디스크에 저장 버튼, 콘솔 오류, 다운로드가 발생하지 않고 아무 것도 클릭하지 않으면 아무런 변화가 없습니다.

또한 jsPDF를 사용하여 인쇄하고 싶다고 말했지만 모든 jsPDF 및 downloadify는 페이지를 PDF 파일로 변환하여 이 아니며이 아닙니다.