SVG (PNG, JPEG) ... picture format export support?
Sometimes I need to export the content not as a json string but as a picture. The PNG and JPEG are natively supported and it is easy to export canvas to this format. But what about any vector format such as SVG?
Hi @tomkey71,
that would be incredibly difficult to implement (however, you're free to do so and thank you very much if you actually do, it would be a nice and useful feature to have). You'd basically have to reimplement the whole rendering to get a vector image out of it (everything just spits pixels to the canvas at the moment).
Just wanted to mention this discussion in the old vis repo and some potentially helpful resources.
So there are projects trying to enable vector image creation (svg, pdf) with canvas API. With them, an export to these formats can be done by creating a mock temporary ctx and calling redraw on it. (https://github.com/justinharrell/vis-svg/blob/master/svg-export.html#L113) See
- https://github.com/justinharrell/vis-svg
- https://github.com/gliffy/canvas2svg
- https://github.com/joshua-gould/canvas2pdf
They may well be immature and lack support for some APIs though.
Both the linked libraries seem pretty dead to me (canvas2svg has no commits since 2017, canvas2pdf will be commit free for a year next week).
Both the linked libraries seem pretty dead to me (canvas2svg has no commits since 2017, canvas2pdf will be commit free for a year next week).
Very true. I guess it is also very relevant to the rate of change in the format standards and canvas APIs, all of which I'm not familiar with.
However, yesterday I successfully exported my network (generated with R's visNetwork) to PDF using the code from https://github.com/justinharrell/vis-svg/blob/master/svg-export.html, so I hope this can be of help to someone in need.
Would love this feature
Seems to be a good alternative as well for better sharing in standard PDF format.