I have SVG images produced by PlantUML, which has some parts of drawing outside of canvas. It makes it difficult to use such images and I need to crop drawing to canvas size. As I produce UML diagrams with script anyways, it would be really efficient to perform a cropping there as well.
So far I've tried two things: a) resize canvas to drawing with Inkscape
inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg
This works fine, but I need to crop drawing to canvas size and this operation seems to be unavailable.
b) resize with rsvg-convert
rsvg-convert image.svg -w 1870 -h 1195 -f svg -o image.svg
This does exactly croping to the desired size, but image size increases ~10 times as now there are some binary images embedded into SVG. This is not acceptable for me.
svg
format is a xml-based ascii format, so the easiest way should be just to usesed
or your favourite text manipulation tool to insert or modify a line that sets the bounding box. This wouldn't even touch the other contents of the file. Try doing it manually once on an example svg file (in a text editor) and then translate your actions into a script.