我正在使用 jsPddf.js 在客户端生成 pdf。 我的页面上有一个 svg 饼图,要在 pdf 上打印它,我使用 svgToPdf.js 插件。 但我在浏览器控制台中收到以下错误:
未捕获的类型错误:非法构造函数
导致错误的代码:var fillRGB = new RGBColor(fillColor);
以下是从 svg 生成 pdf 的代码:
function createPdf() {
var svg = $('#completed svg').get(0);
var doc = new jsPDF();
doc.text(20, 20, 'This is the default font.');
doc.setFont("courier");
doc.text(20, 30, 'This is courier normal.');
doc.setFont("times");
doc.setFontType("italic");
doc.text(20, 40, 'This is times italic.');
doc.setFont("helvetica");
doc.setFontType("bold");
doc.text(20, 50, 'This is helvetica bold.');
doc.setFont("courier");
doc.setFontType("bolditalic");
doc.text(20, 60, 'This is courier bolditalic.');
svgElementToPdf(svg, doc, {
//cale: 72 / 96, // this is the ratio of px to pt units
removeInvalid: true // this removes elements that could not be translated to pdf from the source svg
});
doc.save('Test.pdf');
}
最佳答案
svgElementToPdf 使用 RGBColor 类进行颜色解析,这可能是导致问题的原因。您可以从 here 获取该类(class)
只需将 javascript 文件添加到您的 javascript 资源中,您就可以开始了。
此外,要了解更多相关信息,请参阅 here
关于javascript - SvgToPdf 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25153451/