2016-06-21 99 views
0

您好,我想生成特定div的PDF文件。爲此我發現,jsPDF可能是有用的。我是jsPDF的新手,並且使用谷歌搜索,我發現了一些代碼對我來說可以正常工作。 jsPDF代碼會將d​​iv轉換爲圖像,然後將其保存爲pdf。 MZ的問題是,我有一個單選按鈕在該div中,但是當我將div轉換爲PDF時,該頁面的設計將看起來一樣低於圖像。enter image description here使用jsPDF無法正常顯示Radiobutton

我不知道什麼是確切的問題。這是我寫的代碼。

   var imgData = canvas.toDataURL('image/png'); 

       /* 
       Here are the numbers (paper width and height) that I found to work. 
       It still creates a little overlap part between the pages, but good enough for me. 
       if you can find an official number from jsPDF, use them. 
       */ 
       var imgWidth = 210; 
       var pageHeight = 295; 
       var imgHeight = canvas.height * imgWidth/canvas.width; 
       var heightLeft = imgHeight; 

       var doc = new jsPDF('p', 'mm'); 
       var position = 0; 

       doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); 
       heightLeft -= pageHeight; 

       while (heightLeft >= 0) { 
        position = heightLeft - imgHeight; 
        doc.addPage(); 
        doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); 
        heightLeft -= pageHeight; 
       } 
       doc.save('file.pdf'); 
+0

我等待有人迴應。 – Ankit

回答