SVG-to-PDFKit
SVG-to-PDFKit copied to clipboard
Asynchronous callbacks?
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!
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.
This workaround works well for me, thanks a lot!