使用 jsPDF 无法正确显示单选按钮
Radiobutton is not visible properly using jsPDF
您好,我想生成特定 div 的 PDF 文件。为此我发现,jsPDF 可能很有用。我是 jsPDF 和 bz 谷歌搜索的新手,我发现了一些适合我的代码行。 jsPDF 代码会将 div 转换为图像,然后将其另存为 pdf。 Mz 问题是我在 div 中有一个单选按钮,但是当我将 div 转换为 PDF 时,该页面的设计将类似于下面的图像..
我不知道确切的问题是什么。这是我写的代码。
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');
尝试更改 jspdf 和 canvas javscript link。
我用它修复了它
https://raw.githubusercontent.com/CodeYellowBV/html2canvas/master/build/html2canvas.js
https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js
您好,我想生成特定 div 的 PDF 文件。为此我发现,jsPDF 可能很有用。我是 jsPDF 和 bz 谷歌搜索的新手,我发现了一些适合我的代码行。 jsPDF 代码会将 div 转换为图像,然后将其另存为 pdf。 Mz 问题是我在 div 中有一个单选按钮,但是当我将 div 转换为 PDF 时,该页面的设计将类似于下面的图像..
我不知道确切的问题是什么。这是我写的代码。
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');
尝试更改 jspdf 和 canvas javscript link。 我用它修复了它
https://raw.githubusercontent.com/CodeYellowBV/html2canvas/master/build/html2canvas.js
https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js