使用jsPDF无法正确显示Radiobutton

时间:2016-06-21 15:55:25

标签: javascript html pdf-generation jspdf

您好我想生成特定div的PDF文件。为此我发现,jsPDF可能是有用的。我是jsPDF的新手和bz谷歌搜索我发现代码行对我来说很好。 jsPDF代码将div转换为图像,然后将其保存为pdf。 Mz问题是我在div中有一个单选按钮但是当我将div转换为PDF时,该页面的设计在图像下方看起来很相似.. enter image description here

我不知道究竟是什么问题。这是我写的代码。

                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');

1 个答案:

答案 0 :(得分:1)