12
$\begingroup$

In the document I found that SVG files can be exported, but there is no information of Import. How can I do that?

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, [by clicking the checkmark sign](tinyurl.com/4srwe26 $\endgroup$ – Dunlop Jan 7 at 5:37
  • 2
    $\begingroup$ If you look at the documentation (I am using MMA 12) SVG is not listed as a format that can be imported. You can check which file formats are supported by using the command $ImportFormats $\endgroup$ – Dunlop Jan 7 at 5:38
  • $\begingroup$ @Dunlop Thank you for your advice. I just want to know how can I do it, it's not limited to be done with Import. I didn't found any related information on this forum, so I think maybe I have to use some external programs to do this. Or I may need to learn something about svg and do it by myself. $\endgroup$ – bcegkmqs23 Jan 7 at 7:50
14
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thank you. I've forgotten this site. I knew this website just yesterday. $\endgroup$ – bcegkmqs23 Jan 7 at 8:12
5
$\begingroup$

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"]

enter image description here

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).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.