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.
ls
in your for-loop-head is superflous and should be abandoned. Just use "for f in "*.pdf"; do ..."