Saturday, July 26, 2014

Crop svg files on the commandline in osx

This script saves you a lot time if you have a lot of svg file to process. It fits the page size of the svg file to your drawing (i.e. 0 margin). Here is the code:

#!/usr/bin/env python3

import subprocess
import sys

# for fn in sys.argv[1:]:
#     inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg['/Applications/',
                 '--verb=FileClose'] + sys.argv[1:])

On Linux it’s simpler, you can replace the long string ‘/Applications/; with ‘inkscape’.