Archive

Posts Tagged ‘pdf’

Vector graphics: batch manipulation on command line

Once in a while I need to manipulate multiple vector graphics at once (mostly svg, but could be embedded in pdf as well). For this purpose I list those commands I regularly resort to below, either directly as command or embedded into small command line scripts. Most of the examples require the vector graphics editor Inkscape to be installed.

Crop all graphics to area actually containing information

To crop the canvas size of a graphics to the area actually containing information (“drawing area” with Inkscape). Inkscape’s --without-gui option does not work yet because Inkscape headless graphics manipulation does not always change graphics, and therefore saving does not trigger anything.

Script fitImg2Canvas

inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose "$@"

Script call

fitImg2Canvas *svg

Update: in the meantime, pdfcrop was added to the Ubuntu repos in the texlive-extra-utils package, which is perfect for the job. pdfcrop automatically recognizes to which area a file can be cropped and further has a margins parameter, which – if given – specifies the margins that should remain in the file:

sudo apt-get install texlive-extra-utils
pdfcrop --margins '10 10 10 10' infile.pdf outfile.pdf

Convert all graphics (svg) to pdf (still containing vector graphics)

Batch converting all svg to pdf files can be useful e.g. with LaTeX (does not support svg graphics per default).

Script svg2pdf

for filename in "$@"
do
        b=$(basename "$filename" .svg)
        inkscape --without-gui --export-pdf="$b.pdf" "$filename"
done

Script call

svg2pdf *svg