Skip to content

Instantly share code, notes, and snippets.

@Elrinth
Forked from JohannesDeml/README.md
Last active October 25, 2023 14:14
Show Gist options
  • Save Elrinth/77092f316b8b10f1d7a24b5a778eba55 to your computer and use it in GitHub Desktop.
Save Elrinth/77092f316b8b10f1d7a24b5a778eba55 to your computer and use it in GitHub Desktop.
Batch converter for windows using inkscape and the command line

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

Batch converter for windows using InkScape and the command line
Just download the file InkscapeBatchConvert.bat Put it in the folder where you have files you wish to convert. Then double click the file to start it. This is compatible with latest version of InkScape

Modifications to the original batch file:

  • Allow for direct conversion from eps to svg.
  • Added ability to quit at any question by typing q.
  • Shows total count of files it will affect before starting to doing anything.
  • Shows x/total during conversion of the current file.
  • Outputs to full path (Thanks leifcr)
  • Added inputs emf and wmf (Thanks leifcr)

You can later use something like https://glyphter.com/ to create webfont from the final svg files.

Troubleshooting

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

@Echo off
set "inkscapePath=C:\Program Files\Inkscape\inkscape.exe"
set /a count=0
set validInput1=svg
set validInput2=pdf
set validInput3=eps
set validInput4=emf
set validInput5=wmf
set validOutput1=eps
set validOutput2=pdf
set validOutput3=png
set validOutput4=svg
echo.
echo This script allows you to convert all files in this folder from one file type to another.
echo (type q to quit at any question)
echo.
set valid=0
echo Allowed file types for source: %validInput1%, %validInput2%, %validInput3%, %validInput4%, %validInput5%
:whileInNotCorrect
set /p sourceType=What file type do you want to use as a source?
if "%sourceType%" EQU "%validInput1%" set valid=1
if "%sourceType%" EQU "%validInput2%" set valid=1
if "%sourceType%" EQU "%validInput3%" set valid=1
if "%sourceType%" EQU "%validInput4%" set valid=1
if "%sourceType%" EQU "%validInput5%" set valid=1
if "%sourceType%" EQU "q" exit /b
if %valid% EQU 0 (
echo Invalid input! Please use one of the following: %validInput1%, %validInput2%, %validInput3%, %validInput4%, %validInput5%
goto :whileInNotCorrect
)
echo.
set valid=0
echo Allowed file types for output: %validOutput1%, %validOutput2%, %validOutput3%, %validOutput4%
:whileOutNotCorrect
set /p outputType=What file type do you want to convert to?
if "%outputType%" EQU "%validOutput1%" set valid=1
if "%outputType%" EQU "%validOutput2%" set valid=1
if "%outputType%" EQU "%validOutput3%" set valid=1
if "%outputType%" EQU "%validOutput4%" set valid=1
if "%outputType%" EQU "q" exit /b
if %valid% EQU 0 (
echo Invalid input! Please use one of the following: %validOutput1%, %validOutput2%, %validOutput3%, %validOutput4%
goto :whileOutNotCorrect
)
if "%outputType%" EQU "%sourceType%" (
echo Input and Output are the same, no point in doing anything. Exiting...
exit /b
)
echo.
set toDelOrNot=n
if "%sourceType%" NEQ "pdf" (
if "%outputType%" EQU "%validOutput4%" (
set valid=0
:whilePdfDelNotCorrect
set /p toDelOrNot=EPS to SVG also generates pdfs, delete these after conversion? (y/n^)
if "%toDelOrNot%" EQU "y" set valid=1
if "%toDelOrNot%" EQU "n" set valid=1
if "%toDelOrNot%" EQU "q" exit /b
if %valid% EQU 0 (
echo Invalid input! Please type either y or n.
goto :whilePdfDelNotCorrect
)
)
)
:: Set DPI for exported file
:whileNotValidDpiNumber
set /p dpi=With what dpi should it be exported (e.g. 300)?
if "%dpi%" EQU "q" exit /b
IF %dpi% NEQ +%dpi% (
echo Invalid input! Please input an actual number.
goto :whilenotValidDpiNumber
)
echo.
:: count how many files we need to convert before converting!
set /a total=0
for /R %%i in (.\*.%sourceType%) do (
set /a total=total+1
)
echo Conversion started. Will do %total% file(s).
echo.
set /a curNr=1
setlocal ENABLEDELAYEDEXPANSION
:: Running through all files found with the defined ending
for /R %%i in (.\*.%sourceType%) do (
set /a count=count+1
echo %%i -^> %%~pi%%~ni.%outputType% ^[!curNr!/%total%^]
:: we didn't select svg:
if "%outputType%" NEQ "%validOutput4%" (
"%inkscapePath%" --without-gui --file="%%i" --export-%outputType%="%%~pi%%~ni.%outputType%" --export-dpi=%dpi%
)
:: for svg export first pdf, then svg...
if "%outputType%" EQU "%validOutput4%" (
if "%sourceType%" NEQ "pdf" (
"%inkscapePath%" --without-gui --file="%%i" --export-pdf="%%~pi%%~ni.pdf" --export-dpi=%dpi%
)
"%inkscapePath%" --without-gui -z -f "%%i" -l "%%~pi%%~ni.%validOutput4%"
if "%toDelOrNot%" EQU "y" (
del "%%~ni.pdf" /f /q
)
)
set /a curNr=curNr+1
)
echo.
echo %count% file(s) converted from %sourceType% to %outputType%!
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment