Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Batch converter for windows using inkscape and the command line

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

Screenshot Batch converter for Windows using Inkscape with the command line
InkscapeBatchConvert is an easy to use solution to quickly convert all files of a folder to another type without the need to open Inkscape. The program uses Windows Batch scripting and will only work on Windows.
Tested with Inkscape 0.9.x - 1.0.x

Usage

  1. Download _InkscapeBatchConvert.bat
  2. Put it in the folder where you have files you wish to convert.
  3. Then double click the file to start it.

Troubleshooting

Problem Solution
Windows blocks the program Right click the file → Properties → Unblock
Windows protected your PC Disable blocking
I can't convert EPS / PDF files. The program says it runs the conversion, but there are no files in the out folder. Make sure you have ghost script installed and added to your environment path. For more information read the Inkscape FAQ
Add ghostscript to path
Can't find Inkscape installation All common file paths are checked for the installation. If you haven't installed Inkscape download it here, otherwise you can also define your own path in the script by setting inkscapePath1 yourself
Can't find inkscape installation custom inkscape path
I'm missing a setting in the script, e.g. defined output width Have a look at the Commandline Documentation or read the inkscape help file inkscape --help and add the needed properties to the script
Inkscape help output Script change position

Todo

Use shell or pipe to avoid starting inkscape for every file as pointed out by @vaifrax here. I would be very happy to get help for that 🙂

Credits

:: From https://gist.github.com/JohannesDeml/779b29128cdd7f216ab5000466404f11
:: Convert vector file formats in the current folder and their subsfolders
@Echo off
setlocal ENABLEDELAYEDEXPANSION
:: Possible paths to check for the installation
set inkscapePath1="C:\Program Files\Inkscape\bin\inkscape.com"
set inkscapePath2="C:\Program Files\Inkscape\inkscape.com"
set inkscapePath3="C:\Program Files (x86)\Inkscape\bin\inkscape.com"
set inkscapePath4="C:\Program Files (x86)\Inkscape\inkscape.com"
if exist %inkscapePath1% (
set inkscapePath=%inkscapePath1%
) else (
if exist %inkscapePath2% (
set inkscapePath=%inkscapePath2%
) else (
if exist %inkscapePath3% (
set inkscapePath=%inkscapePath3%
) else (
if exist %inkscapePath4% (
set inkscapePath=%inkscapePath4%
) else (
echo Can't find Inkscape installation, aborting.
GOTO end
)
)
)
)
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
:: If this can't be run, then the version is an older one
FOR /F "tokens=* USEBACKQ" %%g IN (`%inkscapePath% --version`) do (SET "inkscapeVersion=%%g")
if "%inkscapeVersion%" EQU "" (
set inkscapeVersion=0.x
set /a inkscapeMajorVersion=0
) else (
set /a inkscapeMajorVersion=%inkscapeVersion:~9,1%
)
echo.
echo This script allows you to convert all files in this folder from one file type to another
echo Running with %inkscapeVersion% from %inkscapePath%
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.
:: Older inkscape versions need to generate a pdf before generating svgs
if %inkscapeMajorVersion% EQU 0 (
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 count=0
:: Running through all files found with the defined ending
if %inkscapeMajorVersion% NEQ 0 (
:: Inkscape 1.0 and newer
for /R %%i in (*.%sourceType%) do (
set /a count=count+1
:: Create out folder if it does not exist
if not exist "%%~di%%~piout" mkdir "%%~di%%~piout"
echo %%i -^> %%~di%%~piout\%%~ni.%outputType% ^[!count!/%total%^]
%inkscapePath% --export-filename="%%~di%%~piout\%%~ni.%outputType%" --export-dpi=%dpi% "%%i"
)
) else (
:: Inkscape 0.9.x and older
for /R %%i in (*.%sourceType%) do (
set /a count=count+1
:: Create out folder if it does not exist
if not exist "%%~di%%~piout" mkdir "%%~di%%~piout"
echo %%i -^> %%~di%%~piout\%%~ni.%outputType% ^[!count!/%total%^]
if "%outputType%" NEQ "%validOutput4%" (
%inkscapePath% --without-gui --file="%%i" --export-%outputType%="%%~di%%~piout\%%~ni.%outputType%" --export-dpi=%dpi%
) else (
if "%sourceType%" NEQ "pdf" (
%inkscapePath% --without-gui --file="%%i" --export-pdf="%%~di%%~piout\%%~ni.pdf" --export-dpi=%dpi%
)
%inkscapePath% --without-gui -z -f "out\%%~ni.pdf" -l "%%~di%%~piout\%%~ni.%validOutput4%"
if "%toDelOrNot%" EQU "y" (
del "%%~ni.pdf" /f /q
)
)
)
)
echo.
echo %count% file(s) converted from %sourceType% to %outputType%! (Saved in out folder)
echo.
:end
pause
@myselfhimself

This comment has been minimized.

Copy link

@myselfhimself myselfhimself commented Jul 11, 2018

Awesome!! Thank you for posting!! Would you know of a Unix (BA)SH version for that?

@myselfhimself

This comment has been minimized.

@absurdhart

This comment has been minimized.

Copy link

@absurdhart absurdhart commented Aug 20, 2018

@JohannesDeml I was wondering is there a way to modify this script so it looks in all subfolders as well?

@vaifrax

This comment has been minimized.

Copy link

@vaifrax vaifrax commented Sep 4, 2018

Thanks, this works but is slow.
There's also the --shell option. In a script you could either build a text file containing the commands and pass the file as the argument (inkscape --shell all-commands.txt) or you can pipe to inkscape. This avoids starting inkscape every time and greatly speeds up the whole process.

@sne11ius

This comment has been minimized.

Copy link

@sne11ius sne11ius commented Sep 24, 2018

Worked good for me. Thanks a lot!

@Gabrusp

This comment has been minimized.

Copy link

@Gabrusp Gabrusp commented Oct 25, 2018

Thank you so much!!!

@Jacqvb

This comment has been minimized.

Copy link

@Jacqvb Jacqvb commented Nov 14, 2018

Thanks! saved me a lot of time.

@foreachthing

This comment has been minimized.

Copy link

@foreachthing foreachthing commented Nov 17, 2018

Thanks! Very helpful!

@eric-chauveau

This comment has been minimized.

Copy link

@eric-chauveau eric-chauveau commented May 18, 2019

Many thanks^. Perfect!

@janncors

This comment has been minimized.

Copy link

@janncors janncors commented May 18, 2019

Thank you so much, awesome!!

@Elrinth

This comment has been minimized.

Copy link

@Elrinth Elrinth commented Jul 3, 2019

Thank you so much for this code!

I improved it to allow conversion directly from eps to svg. Also added some more information such as how many files it is before it starts, and that it is currently working on file x/total. Plus it has some more error handling. Check my fork.

I used it later to create a web font with https://glyphter.com/ . I simply drag 'n dropped all the svgs into glyphter and it created .css, .ttf, .eot, .svg, .woff . Glyphter is a bit buggy as some svgs weren't rendered correctly, plus not super intuitive, but I felt the results were better than FontForge.

@sskolpakchi

This comment has been minimized.

Copy link

@sskolpakchi sskolpakchi commented Sep 25, 2019

Thank you! Very usefull tool. It would be very nice if I could set the file mask for conversion.

@FrancoisJULIENNE

This comment has been minimized.

Copy link

@FrancoisJULIENNE FrancoisJULIENNE commented Nov 29, 2019

Good work ! thank you so much !

@rednaxelaesor

This comment has been minimized.

Copy link

@rednaxelaesor rednaxelaesor commented Jan 8, 2020

Works great.
Is there a way to adjust the image size (analog to DPI)? What would the corresponding command be?
I would like to make all images 1600 pixels wide

Hab's gefunden: --export-width=BREITE

@stenright

This comment has been minimized.

Copy link

@stenright stenright commented Jan 24, 2020

My svgs have links. When I run the tool it does not preserve the links. Do you know if this is a switch that can be added to the script?
Thanks!
Tim

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Jan 24, 2020

My svgs have links. When I run the tool it does not preserve the links. Do you know if this is a switch that can be added to the script?
Thanks!
Tim

Seems like there is no easy way, but maybe that project does what you're looking for: https://github.com/oxplot/svglinkify

@dlwillequer

This comment has been minimized.

Copy link

@dlwillequer dlwillequer commented Feb 8, 2020

Just wanted to stop in to say THANK YOU! This worked perfectly for converting the 1544 Line Awesome icons from SVG to PNG at 1000px x 1000px. Probably overkill, but I will be doing some additional batch processing on them to shrink them and modify them and want to ensure I don't have any quality loss.

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Feb 9, 2020

Just wanted to stop in to say THANK YOU! This worked perfectly for converting the 1544 Line Awesome icons from SVG to PNG at 1000px x 1000px. Probably overkill, but I will be doing some additional batch processing on them to shrink them and modify them and want to ensure I don't have any quality loss.

Happy to here that, you're very welcome and thanks for the comment :)

@3dfernando

This comment has been minimized.

Copy link

@3dfernando 3dfernando commented Mar 11, 2020

Two words for you: THANK YOU!! Like... Really. Made my paper submission process 1e9 times faster!!

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Mar 11, 2020

Two words for you: THANK YOU!! Like... Really. Made my paper submission process 1e9 times faster!!

Happy to hear it helped your scientic efforts! You're very welcome :)

@TylerStephans

This comment has been minimized.

Copy link

@TylerStephans TylerStephans commented Apr 27, 2020

Worked like a dream. Thanks!

@PedroAugustoMarques

This comment has been minimized.

Copy link

@PedroAugustoMarques PedroAugustoMarques commented May 12, 2020

I was having trouble using this script in 1.0. Seems like 1.0 changed some commands. I fixed it by changing line 46 from:

"%inkscapePath%" --without-gui --file="%%i" --export-%outputType%="%%~ni.%outputType%" --export-dpi=%dpi%

To:

"%inkscapePath%" --export-filename="%%~ni.%outputType%" --export-dpi=%dpi% "%%i"

@Elrinth

This comment has been minimized.

Copy link

@Elrinth Elrinth commented May 14, 2020

I updated my fork to include improvements from @leifcr (full outputpath aswell as support for two more input formats: emf and wmf) and my fork is compatible with InkScape 1.0.

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 14, 2020

I updated my fork to include improvements from @leifcr (full outputpath aswell as support for two more input formats: emf and wmf) and my fork is compatible with InkScape 1.0.

Awesome, wanted to do that as well! Is it also backwards compatible to Inkscape 0.9.x? Is it okay for you if I "pull" and merge your changes here and add you to the readme? :)

@Elrinth

This comment has been minimized.

Copy link

@Elrinth Elrinth commented May 14, 2020

Yes absolutely, please as most people will just grab your version.

Yes it is backwards compatible with 0.9.x. I made no changes whatsoever when I updated and tested with InkScape 1.0 today. So I'm assuming I had already fixed these problems.

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 14, 2020

Yes absolutely, please as most people will just grab your version.

Yes it is backwards compatible with 0.9.x. I made no changes whatsoever when I updated and tested with InkScape 1.0 today. So I'm assuming I had already fixed these problems.

Great, I think so as well. Good to have the best version in the most visible space. I also added leifcr to the credits, since he seemed to work on your fork as well 👍

The additions with the new file formats are great (especially svg as an output, already needed that once).

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 15, 2020

@Elrinth I tested the program, and even though it didn't throw any errors, it actually didn't do anything. I did a major cleanup and built it to support inkscape 0.x and 1.x.
@PedroAugustoMarques thanks for the info, that code actually worked for me for 1.0, the program now fully supports 1.0 👍

@FoxP

This comment has been minimized.

Copy link

@FoxP FoxP commented May 16, 2020

Does not work if "out" directory does not exist. :)
Edit inkscape.exe to inkscape.com in inkscapePath1 for better error log.

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 16, 2020

Does not work if "out" directory does not exist. :)

Interesting that the folder problem exists for you. I tried on two different windows 10 machines and did not have the problem. I added the check for creating the out folder, that should fix your problem.

Edit inkscape.exe to inkscape.com in inkscapePath1 for better error log.
@FoxP This is a path to the exe file, so I don't see why changing it to inkscape.com would make any sense. Or are you talking about something else than the batch script?

@FoxP

This comment has been minimized.

Copy link

@FoxP FoxP commented May 17, 2020

I guess it's a Windows 8.1 issue.
Also, script has random crashes using Inkscape 1.0 on a thousand svg to png conversions.
Reverting to Inkscape 0.9 fixes the issue so i guess it's Inkscape-related.

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 17, 2020

Good to know, thanks for sharing! I think the problem could be solved by not starting a new inkscape process every time as pointed out by @vaifrax. This would also improve the speed a lot, especially for thousands of files this would make a lot of sense. Sadly I don't have the time to implement that. If anyone gets it up and running I'm happy to merge it here :)

@anandnr47

This comment has been minimized.

Copy link

@anandnr47 anandnr47 commented Nov 2, 2020

Is .vsd or .vsdx format conversion possibe? If yes, please let me know what changes I should make?

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Nov 2, 2020

I've never worked with vsd, but I guess it should be able to import vsd files (since Inkscape supports that), but it won't be able to export to vsd files.

You would need to add .vsd to the options for validInput. I guess the fastest way is to replace " set validInput5=wmf" with " set validInput5=vsd".

@jpeni

This comment has been minimized.

Copy link

@jpeni jpeni commented Nov 3, 2020

Johannes - Thank you for your useful InkScape script. The only request I could make in your next script is a user prompt for additional InkScape command parameters. For example, I would like to add the "--export-area-drawing" parameter when I convert most files so the output files display all visible objects of the image without margins or cropping.

@mafraqs

This comment has been minimized.

Copy link

@mafraqs mafraqs commented Dec 9, 2020

Huge thanks for the script - an absolute time saver!

I found when exporting emf to svg the script only exportet pdf files for me. Mabye a bug?
Fixed it by changing the all %validOutput4% to %validOutput3% from line 92 down.
No more pdfs but all my beautiful svg files were exported after :)

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Dec 9, 2020

Huge thanks for the script - an absolute time saver!

I found when exporting emf to svg the script only exportet pdf files for me. Mabye a bug?
Fixed it by changing the all %validOutput4% to %validOutput3% from line 92 down.
No more pdfs but all my beautiful svg files were exported after :)

Nice catch, seems like the extra step of generating a pdf before generating the svg is not needed anymore (and breaks stuff). I updated the script, should work as expected now :)
And you're welcome, happy to hear, that the script saves you time!

@cshyun102

This comment has been minimized.

Copy link

@cshyun102 cshyun102 commented Apr 8, 2021

Really Really thank you Johannes! It saves huge amount of time to write article in tex!

@turbogauchiste

This comment has been minimized.

Copy link

@turbogauchiste turbogauchiste commented Apr 12, 2021

Thanks, this works but is slow.
There's also the --shell option. In a script you could either build a text file containing the commands and pass the file as the argument (inkscape --shell all-commands.txt) or you can pipe to inkscape. This avoids starting inkscape every time and greatly speeds up the whole process.

Hi, i'm kind of a newbie, could someone explain a bit much, i don't really get how to do that. Apart from this, thanks so much for your script

@vlschmidt

This comment has been minimized.

Copy link

@vlschmidt vlschmidt commented Apr 28, 2021

@JohannesDeml, for me the inscape.com binary actually outputs errors to the console, while the *.exe does not:

PS C:\Program Files\Inkscape\bin> .\inkscape.com --version
Inkscape 1.0.2-2 (e86c870879, 2021-01-15)
Pango version: 1.48.2
PS C:\Program Files\Inkscape\bin> .\inkscape.exe --version

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Apr 28, 2021

@JohannesDeml, for me the inscape.com binary actually outputs errors to the console, while the *.exe does not:

PS C:\Program Files\Inkscape\bin> .\inkscape.com --version
Inkscape 1.0.2-2 (e86c870879, 2021-01-15)
Pango version: 1.48.2
PS C:\Program Files\Inkscape\bin> .\inkscape.exe --version

A, very interesting, didn't know that there also was a executable .com extension. I found the information about verbose output here: https://inkscape.org/learn/faq/#how-use-inkscape-command-line
Thanks for the hint, I changed the program to use the com extension :)

@LansendInc

This comment has been minimized.

Copy link

@LansendInc LansendInc commented May 10, 2021

Thank you , worked like a charm , saved me a lot of grief.
Just an FYI , it goes nuts if there is a space in the folder name.
I simply renamed " Folder Name" to Folder_Name" and was all set.

Thanks much

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 11, 2021

Thank you , worked like a charm , saved me a lot of grief.
Just an FYI , it goes nuts if there is a space in the folder name.
I simply renamed " Folder Name" to Folder_Name" and was all set.

Thanks much

Ah, nice catch! Should be fixed now :)

@turbogauchiste

This comment has been minimized.

Copy link

@turbogauchiste turbogauchiste commented May 11, 2021

Thanks, this works but is slow.
There's also the --shell option. In a script you could either build a text file containing the commands and pass the file as the argument (inkscape --shell all-commands.txt) or you can pipe to inkscape. This avoids starting inkscape every time and greatly speeds up the whole process.

How would you do that?

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented May 11, 2021

Thanks, this works but is slow.
There's also the --shell option. In a script you could either build a text file containing the commands and pass the file as the argument (inkscape --shell all-commands.txt) or you can pipe to inkscape. This avoids starting inkscape every time and greatly speeds up the whole process.

How would you do that?

Hi @turbogauchiste,

that's a bit different to build up, I've never done it, so I didn't feel like the first question of yours was directed at me. Anyhow, if you need that extra performance, take a look at https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line#Shell_mode, there is the documentation of how to use the shell (batch) mode.

@Elmstrom

This comment has been minimized.

Copy link

@Elmstrom Elmstrom commented Jun 3, 2021

This is awesome! thanks a lot for sharing.

@adamovichg

This comment has been minimized.

Copy link

@adamovichg adamovichg commented Jul 30, 2021

I had to upgrade to Inkscape 1.1 for this to work. Was previously working in Inkscape 0.92.4. Don't know, perhaps this is obvious, but it's good to know :)

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Aug 2, 2021

I had to upgrade to Inkscape 1.1 for this to work. Was previously working in Inkscape 0.92.4. Don't know, perhaps this is obvious, but it's good to know :)

Interesting, thanks for letting me know! I tried to keep backwards compatibility, but I guess I broke something along the way. I hope, I'll find the time to do a 0.9.x setup to see whats wrong at some point :)

@TimoRJensen

This comment has been minimized.

Copy link

@TimoRJensen TimoRJensen commented Aug 26, 2021

Awesome stuff! Thanks a lot for sharing! Had to update too (from 0.9 to 1.1), but that did the trick. Before that I had errors like invalid argument --export-filename... (can't recall exactly now.)

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

@JohannesDeml JohannesDeml commented Aug 28, 2021

@TimoRJensen, thank you also for your note. I found the time to fix the logic for 0.x versions (the problem was, that the version call does not properly work for 0.x and then the script used the logic for 1.x for 0.x). Should be all fixed now and is now compatible for all versions again :)

@loganpowell

This comment has been minimized.

Copy link

@loganpowell loganpowell commented Sep 24, 2021

Just found this!! Is there a way to run the batch over svg -> optimized svg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment