yWorks / jsPDF

JavaScript PDF generation to work with SVG
MIT License
56 stars 23 forks source link

jsPDF always logs warning when used with svg2pdf #31

Closed sschmidTU closed 4 years ago

sschmidTU commented 4 years ago

When using svg2pdf, which depends on jspdf, i always get this warning in the console right in the import phase: image

I know this is not entirely jspdf's fault, it's probably due to svg2pdf importing jspdf, and if you want to use svg2pdf, you have to import jspdf as well, in which case the AcroForm classes are already added.

But I see no way to prevent this warning from appearing, since it occurs during imports/requires, and it would be unfortunate if i have to see this warning for the rest of my days when using jspdf and another package that imports jspdf.

Is this warning actually helpful for anyone? Can't it be removed, or saved and then only output if an option is set to show such warnings? Maybe we can save which version of jspdf was adding the classes and only warn if two different versions try to add different AcroForm classes?

// acroform.js:3104
else {
    // eslint-disable-next-line no-console
    console.warn(
      "AcroForm-Classes are not populated into global-namespace, because the class-Names exist already. This avoids conflicts with the already used framework."
    );
  }

I know this isn't the most pleasant kind of issue, but thanks for your consideration.

HackbrettXXX commented 4 years ago

IMO the acroform module shouldn't even register any classes to the global namespace since they are always available via jsPDF. For backward compatibility we should keep it, though. But I guess we can at least remove the warning entirely. I think there are very few use cases where this warning is helpful compared to the amount of false positives.

Can you prepare a pull request?

sschmidTU commented 4 years ago

Yes, registering to global namespace is a bit unideal because it can also create conflicts when different versions are used simultaneously.

Thanks for the consideration! I created PR #32.