For the first time I needed to perform a diff on an SVG file created with Inkscape, because I had a conflict in SVN.

While checking the differences, I noticed that the SVG file contains a lot of personal information. The personal information is about paths used for exporting. The SVG source looks like this:

<text ... inkscape:export-filename="<personal information here>" ... />

In my case it has a lot of folder names going back to projects I worked for in 2009.

How can I remove this personal information from Inkscape SVG files?

Of course I could do it in a text editor manually, but that has some disadvantages:

  • it's error-prone. You need to be quite sure what you're doing. There should be a safer way to do it.
  • it's time-consuming. There should be a quicker way to do it.
  • it might be incomplete. Maybe there is other personal data I have not discovered yet.

The easiest way to do this is to save the file as an Optimized SVG file. This option is available in the Save As... dialog dropdown. When you click save a dialog will popup asking you what to remove. Make sure the box Keep Editor Data is left unchecked.

  • I must have missed that one, because it's far down in the options. I tried it and it works. Apr 9 '14 at 20:28

I have a lot of SVGs from different sources, so I was looking for an automated solution.

1. SVGO (NodeJS, javascript)

There is a very good NPM package: SVGO

Since I use gulp as a task-runner, so the gulp-svgmin (or gulp-svgo) is very helpful

2. XSLT (transform SVG)

The other automated approach — use XSLT. Here is an XSL transformation I have used to cleanup SVG.

This XSLT does the following:

  1. removes all inkscape and sodipodi attributes
  2. removes all inkscape and sodipodi elements
  3. removes metadata element with all ancestors
  4. removes style attributes (we use CSS) - only when the variable preserve-style is set to false

As output you will get the clean SVG file.

How to run transformation

Javascript (gulp build)

If you use gulp as build system, you could use this plugins:

Python and lxml.etree

Use this short python script:


import lxml.etree as ET

def clean_file(path, pathto):
    svg1 = ET.parse(path)

    xslt = ET.parse('cleanup-svg.xsl')
    transform = ET.XSLT(xslt)
    svg2 = transform(svg1)
    with open(pathto, 'w') as f:
        f.write(ET.tostring(svg2, pretty_print=True))

clean_file('a.svg', 'b.svg')

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.