简体   繁体   English

如何解决jspdf名称冲突

[英]How to solve jspdf name conflict

I'm using different jsPDF libraries in my react app like below:我在我的反应应用程序中使用不同的 jsPDF 库,如下所示:

For table html exports: import jsPDF from 'jspdf';对于表 html 导出: import jsPDF from 'jspdf'; import "jspdf-autotable";导入“jspdf-autotable”;

For svg to pdf exports: const svg2pdf = require('svg2pdf.js');对于 svg 到 pdf 导出: const svg2pdf = require('svg2pdf.js'); const jsPDF = require('jspdf-yworks'); const jsPDF = require('jspdf-yworks');

Both jsPDF and 'jspdf-yworks' have using the same name for creating jsPDF object like; jsPDF 和 'jspdf-yworks' 都使用相同的名称来创建 jsPDF object 之类的;

const doc = new jsPDF('l', 'pt', [width, height]); const doc = new jsPDF('l', 'pt', [width, height]);

is there any solution for the name conflict?名称冲突有什么解决办法吗?

Thanks..谢谢..

You can change the default import name eg import {default as jsPDFautotable} from 'jspdf'您可以更改默认导入名称,例如import {default as jsPDFautotable} from 'jspdf'

Easiest way is probably using const jsPDFyWorks = require('jspdf-yworks') .最简单的方法可能是使用const jsPDFyWorks = require('jspdf-yworks')

But note that you might be able to use yworks jspdf for autotable as well by utilizing the new applyPlugin method.但请注意,您也可以通过使用新的 applyPlugin 方法将 yworks jspdf 用于自动表格。

const jsPDF = require('jspdf-yworks')
const { applyplugin } = require('jspdf-autotable')
applyPlugin(jsPDF)

const doc = new jsPDF()
doc.autoTable({/*  options */})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM