1

I have many files created with adobe illustrator (.ai) on A4 canvas size, and I would like to convert (in CLI) to SVG file to allow their use in a website.

A basic conversion works by running, for example :
inkscape myFile.ai --export-area-drawing --export-plain-svg myFile.svg

My issue is the option export-area-drawing (or verb FitCanvasToDrawing) doesn't let any margin, so display in web page is not nice.

Like GUI properties which allow to add margins, I would like to do the same in CLI, adding 20 pixels on up/down/left/right margins, as capture below at right instead of left margin-example

Is there a way to do that using Inkscape in CLI?

I read https://wiki.inkscape.org/wiki/Using_the_Command_Line, https://inkscape.org/doc/inkscape-man.html, tried to change fit-margin-… in file without success.

Of course, I can change website CSS to add

img {
    position: relative;
    top: 20px;
    left: 20px;
}

But if we open file in other way, the display stays bad, and if CSS framework change…

I also read on post https://graphicdesign.stackexchange.com/a/6670/144183 there is librsvg

I am using Inkscape v1.1.1 installed by snap under Ubuntu 18.04

New contributor
bcag2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0
2

Update:

The question was not clear at the first glance and one may think that export-area-drawing action doesn't work with export-margin. So you can invoke Inkscape as follows:

inkscape myFile.ai --actions="export-area-drawing;export-margin:50;export-type:svg;export-plain-svg; export-do" -o myFile.svg

Old answer:

In Inkscape 1.2-dev there is the action fit-canvas-to-selection. To specify the export margin use the export-margin action.

The following command should work as expected:

inkscape myFile.ai --actions="select-all;fit-canvas-to-selection;export-margin:50;export-type:svg;export-plain-svg; export-do" -o myFile.svg

The other actions in that command are self-explanatory.

If that doesn't work for some reason, there is another workaround:

  • Use Inkscape to convert your *.ai files to PDF.
  • use pdfcrop utility to crop the PDF documents with custom margins. check pdfcrop --help for examples. If you don't have it already installed, try:
    sudo apt-get install texlive-extra-utils 
    
  • Convert the PDF documents to plain SVG using Inkscape.
1
  • Thanks you for your quick answer, I prefer Marc's answer which works on my release.
    – bcag2
    Jan 12 at 13:15
1

Marc JM answer :
inkscape --export-area-drawing --export-margin 20 input.ai -o output.svg
works fine on the v1.1.1 installed on my computer

New contributor
bcag2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Your question was relatively misleading. There is no fit-margin... option in the linked web pages. I mistakenly thought that you're referring to export-margin and that it doesn't work with export-area-drawing
    – s.ouchene
    Jan 12 at 13:45

Your Answer

bcag2 is a new contributor. Be nice, and check out our Code of Conduct.

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.