Skip to content

Instantly share code, notes, and snippets.

@pasrom
Forked from JohannesDeml/README.md
Last active November 6, 2020 13:50
Show Gist options
  • Save pasrom/0965be641547b34618926d404773cd94 to your computer and use it in GitHub Desktop.
Save pasrom/0965be641547b34618926d404773cd94 to your computer and use it in GitHub Desktop.
Batch / bash converter for windows / mac / linux using inkscape and the command line

Batch convert svg|pdf|eps to eps|pdf|png

Batch converter for windows using inkscape and the command line
Just download the file InkscapeBatchConvert.bat and put it in the folder you want to run it at. Then double click the file to start it.

Troubleshooting

Check if your inkscape path is C:\Program Files\Inkscape\inkscape.exe, otherwise change the path in line 3 in the bat script

Added support for latex

@Echo off
set "inkscapePath=C:\Program Files\Inkscape\inkscape.exe"
set /a count=0
set validInput1=svg
set validInput2=pdf
set validInput3=eps
set validOutput1=eps
set validOutput2=pdf
set validOutput3=png
echo This script allows you to convert all files in this folder from one file type to another.
set valid=0
echo Allowed file types for source: %validInput1%, %validInput2%, %validInput3%
:whileInNotCorrect
::set /p sourceType=What file type do you want to use as a source?
set sourceType=%1
if "%sourceType%" EQU "%validInput1%" set valid=1
if "%sourceType%" EQU "%validInput2%" set valid=1
if "%sourceType%" EQU "%validInput3%" set valid=1
if %valid% EQU 0 (
echo Invalid input! Please use one of the following: %validInput1%, %validInput2%, %validInput3%
goto :Error
)
set valid=0
echo Allowed file types for output: %validOutput1%, %validOutput2%, %validOutput3%
:whileOutNotCorrect
::set /p outputType=What file type do you want to convert to?
set outputType=%2
if "%outputType%" EQU "%validOutput1%" set valid=1
if "%outputType%" EQU "%validOutput2%" set valid=1
if "%outputType%" EQU "%validOutput3%" set valid=1
if %valid% EQU 0 (
echo Invalid input! Please use one of the following: %validOutput1%, %validOutput2%, %validOutput3%
goto :Error
)
:: Set DPI for exported file
::set /p dpi=With what dpi should it be exported (e.g. 300)?
set dpi=600
:: Running through all files found with the defined ending
cd %3
for /f "tokens=1* delims=." %%i in ('dir /b /s *.svg') do (
set /a count=count+1
echo %%i to %%i.%outputType%
"%inkscapePath%" --without-gui --file="%%i.svg" --export-pdf="%%i-svg-raw.%outputType%" --export-pdf-version="1.5"
)
:: "C:\Program Files\Inkscape\inkscape.exe" --without-gui --file="C:\workspace\Ablauf_Qbv.svg" --export-pdf="C:\workspace\Ablauf_Qbv-svg-raw.pdf"
echo %count% file(s) converted from %sourceType% to %outputType%!
:Error
#!/bin/bash
sourceType=$1
outputType=$2
docPath=$3
echo "Arguments: $@"
echo "This script allows you to convert all files in this folder from one file type to another."
validInputs=( svg pdf eps );
validOutputs=( eps pdf png );
vailidNr=0;
echo "Allowed file types for source: ${validInputs[@]}"
for input in "${validInputs[@]}"; do
if [[ "$sourceType" == "$input" ]]; then
echo "$sourceType present"
vailidNr=1;
fi
done
if [[ "$vailidNr" != 1 ]]; then
echo "Invalid input! Please use one of the following: ${validInputs[@]}"
exit 1
fi
echo "Allowed file types for output: ${validOutputs[@]}"
for output in "${validOutputs[@]}";
do
if [[ "$outputType" == "$output" ]]; then
echo "$outputType present"
break
fi
done
if [[ "$vailidNr" != 1 ]]; then
echo "Invalid input! Please use one of the following: ${validOutputs[@]}"
exit 1
fi
dpi=600
find $3 -name "*.$sourceType" | while read line
do
name=$(echo $line | cut -f 1 -d '.')
echo $line
echo $name
inkscape -f "$line" --export-pdf="$name-svg-raw.$outputType" -d $dpi --export-pdf-version=1.5
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment