How to import SVG files?
This is not currently supported by the built-in functions, but there is a function called SVGImport
in the function repository that can do this:
https://resources.wolframcloud.com/FunctionRepository/resources/SVGImport
Alternative answer: Use the SVG importer from my Prototypes paclet:
https://github.com/arnoudbuzing/prototypes/releases/tag/0.5.6
To install the paclet, run this command:
PacletInstall["https://github.com/arnoudbuzing/prototypes/releases/download/v0.5.6/Prototypes-0.5.6.paclet"]
Note that this paclet has many many functions, but you may be able to extract just the SVG importer if that's all you need.
After that you can load the package:
Get["Prototypes`"]
Normally this package autoloads when you use a function from the package, but not in this case which uses Import
.
Next run Import
to import the SVG file (example source):
Import["D:\\tmp\\in.svg", "SVG"]
Important note: This implementation uses the Apache-Batik java library and imports the SVG as a raster image and not as a graphics object. So you lose the scalability of the SVG. On the other hand, this implementation does a very faithful rendering of SVG file (exceeding, in certain cases, the result from the SVGImport resource function (which works well in a lot of cases too).
Depending on your usage scenario, converting the SVG files to PDF via Inkscape and then importing the PDF files using the regular Mathematica Import[] function might be a viable alternative.
I tried this with Inkscape 0.92 and Mathematica 12 on Linux, albeit only for one file.
Inkscape can also do the conversion from SVG to PDF using command line options. Therefore, if you have many files, you could automatize the conversion process.