2

in short, I tried

for f in `ls *.pdf`; do inkscape -z --export-background=ffffff --export-background-opacity=1.0 --export-plain-svg=${f}.svg $f; done

It throws no errors, produces SVG files, but doesn't add background to them. Does someone know what's wrong?

It's Inkscape 0.92.4

UPD thanks Billy Kerr for pointing towards the solution. I combined his suggestion with use of GNU sed to process many files automatically. It seems like meaningful data in SVG starts from <defs> tag, so I just add the rectangle before the first <defs occurrence:

for f in "*.pdf.svg"; do sed -i '0,/<defs/s/<defs/<rect width="100%" height="100%" fill="#ffffff"\/>\n  <defs/' $f; done

which means: sed, please find the first occurrence of a pattern (0,/pattern) and substitute it s/pattern/new string \n pattern/, writing to the same file (sed -i flag). It looks like a very ad hoc solution, but it works.

  • The ls in your for-loop-head is superflous and should be abandoned. Just use "for f in "*.pdf"; do ..." – user unknown Aug 20 at 18:59
  • @userunknown thanks, I didn't know that! – Karen Fidanyan Aug 21 at 8:17
2

Inkscape has no background attribute as such, although it does have pagecolor which can be set in the document properties (it shows up as "background" in the UI, but appears as "pagecolor" in the XML). The problem however is that the pagecolor attribute is not supported in SVG and so it will be lost when you export as plain SVG.

Instead you could try editing the SVG in a text editor to add a white filled rectangle the same size as the canvas, and before (i.e. underneath) the artwork layer. Sorry, I don't know how to do that with the command line, but hopefully there's enough information here to help you work it out.

for example:

<rect width="100%" height="100%" fill="#ffffff"/>
  • Doesn't work on the Inkscape command line currently (0.92.x), so no wonder you don't know how ;-) – Moini Aug 19 at 14:45
  • @Moini Then perhaps just copy and pasting the code into the SVGs would be an option for the OP? Obviously it could be rather tedious if there are a lot of SVGs. – Billy Kerr Aug 19 at 21:31

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.