SVG-to-PDFKit icon indicating copy to clipboard operation
SVG-to-PDFKit copied to clipboard

Asynchronous callbacks?

Open r4tz52 opened this issue 5 years ago • 2 comments

Hi,

I'm using the SVG-to-PDFKit with my own font providing service, so my fontCallback function must be async (it will download and register fonts on demand). As far as I see the SVG-to-PDFKit was designed with simple synchronous callbacks. Am I right? Is it hard to make callbacks async?

Thanks!

r4tz52 avatar Apr 24 '19 14:04 r4tz52

The only way to do it currently is the following:

  • call SVG-to-PDFKit in a temporary document
  • create a list of font families and populate it at each callback function
  • load asynchronously the fonts and keep them as ArrayBuffers
  • use SVG-to-PDFKit on the real document with the loaded ArrayBuffers

A better solution would be to reorganize the code in a module (https://github.com/alafr/SVG-to-PDFKit/issues/64#issuecomment-366819703) with functions that can be used independently, for example: SVGtoPDFKit.parse(), SVGtoPDFKit.listRequiredFonts(), SVGtoPDFKit.render(), SVGtoPDFKit.boundingBox(). I don't think it would be very hard to implement but I don't have the time to do it. I would accept discussion/pull request for this subject.

alafr avatar Apr 24 '19 17:04 alafr

This workaround works well for me, thanks a lot!

r4tz52 avatar Apr 25 '19 05:04 r4tz52