1. @Echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. :: Possible paths to check for the installation
  4. set inkscapePath1="C:\Program Files\Inkscape\bin\inkscape.exe"
  5. set inkscapePath2="C:\Program Files\Inkscape\inkscape.exe"
  6. set inkscapePath3="C:\Program Files (x86)\Inkscape\bin\inkscape.exe"
  7. set inkscapePath4="C:\Program Files (x86)\Inkscape\inkscape.exe"
  8. if exist %inkscapePath1% (
  9. set inkscapePath=%inkscapePath1%
  10. ) else (
  11. if exist %inkscapePath2% (
  12. set inkscapePath=%inkscapePath2%
  13. ) else (
  14. if exist %inkscapePath3% (
  15. set inkscapePath=%inkscapePath3%
  16. ) else (
  17. if exist %inkscapePath4% (
  18. set inkscapePath=%inkscapePath4%
  19. ) else (
  20. echo Can't find Inkscape installation, aborting.
  21. GOTO end
  22. )
  23. )
  24. )
  25. )
  26. set validInput1=svg
  27. set validInput2=pdf
  28. set validInput3=eps
  29. set validInput4=emf
  30. set validInput5=wmf
  31. set validOutput1=eps
  32. set validOutput2=pdf
  33. set validOutput3=png
  34. set validOutput4=svg
  35. FOR /F "tokens=* USEBACKQ" %%g IN (`%inkscapePath% --version`) do (SET "inkscapeVersion=%%g")
  36. set /a inkscapeMajorVersion=%inkscapeVersion:~9,1%
  37. echo.
  38. echo This script allows you to convert all files in this folder from one file type to another
  39. echo Running with %inkscapeVersion%
  40. echo (type q to quit at any question)
  41. echo.
  42. set valid=0
  43. echo Allowed file types for source: %validInput1%, %validInput2%, %validInput3%, %validInput4%, %validInput5%
  44. :whileInNotCorrect
  45. set /p sourceType=What file type do you want to use as a source?
  46. if "%sourceType%" EQU "%validInput1%" set valid=1
  47. if "%sourceType%" EQU "%validInput2%" set valid=1
  48. if "%sourceType%" EQU "%validInput3%" set valid=1
  49. if "%sourceType%" EQU "%validInput4%" set valid=1
  50. if "%sourceType%" EQU "%validInput5%" set valid=1
  51. if "%sourceType%" EQU "q" exit /b
  52. if %valid% EQU 0 (
  53. echo Invalid input! Please use one of the following: %validInput1%, %validInput2%, %validInput3%, %validInput4%, %validInput5%
  54. goto :whileInNotCorrect
  55. )
  56. echo.
  57. set valid=0
  58. echo Allowed file types for output: %validOutput1%, %validOutput2%, %validOutput3%, %validOutput4%
  59. :whileOutNotCorrect
  60. set /p outputType=What file type do you want to convert to?
  61. if "%outputType%" EQU "%validOutput1%" set valid=1
  62. if "%outputType%" EQU "%validOutput2%" set valid=1
  63. if "%outputType%" EQU "%validOutput3%" set valid=1
  64. if "%outputType%" EQU "%validOutput4%" set valid=1
  65. if "%outputType%" EQU "q" exit /b
  66. if %valid% EQU 0 (
  67. echo Invalid input! Please use one of the following: %validOutput1%, %validOutput2%, %validOutput3%, %validOutput4%
  68. goto :whileOutNotCorrect
  69. )
  70. if "%outputType%" EQU "%sourceType%" (
  71. echo Input and Output are the same, no point in doing anything. Exiting...
  72. exit /b
  73. )
  74. echo.
  75. :: Older inkscape versions need to generate a pdf before generating svgs
  76. if %inkscapeMajorVersion% EQU 0 (
  77. set toDelOrNot=n
  78. if "%sourceType%" NEQ "pdf" (
  79. if "%outputType%" EQU "%validOutput4%" (
  80. set valid=0
  81. :whilePdfDelNotCorrect
  82. set /p toDelOrNot=EPS to SVG also generates pdfs, delete these after conversion? (y/n^)
  83. if "%toDelOrNot%" EQU "y" set valid=1
  84. if "%toDelOrNot%" EQU "n" set valid=1
  85. if "%toDelOrNot%" EQU "q" exit /b
  86. if %valid% EQU 0 (
  87. echo Invalid input! Please type either y or n.
  88. goto :whilePdfDelNotCorrect
  89. )
  90. )
  91. )
  92. )
  93. :: Set DPI for exported file
  94. :whileNotValidDpiNumber
  95. set /p dpi=With what dpi should it be exported (e.g. 300)?
  96. if "%dpi%" EQU "q" exit /b
  97. IF %dpi% NEQ +%dpi% (
  98. echo Invalid input! Please input an actual number.
  99. goto :whilenotValidDpiNumber
  100. )
  101. echo.
  102. :: count how many files we need to convert before converting!
  103. set /a total=0
  104. for /R %%i in (*.%sourceType%) do (
  105. set /a total=total+1
  106. )
  107. echo Conversion started. Will do %total% file(s).
  108. echo.
  109. set /a count=0
  110. :: Running through all files found with the defined ending
  111. if %inkscapeMajorVersion% NEQ 0 (
  112. :: Inkscape 1.0 and newer
  113. for /R %%i in (*.%sourceType%) do (
  114. set /a count=count+1
  115. :: Create out folder if it does not exist
  116. if not exist %%~di%%~piout mkdir %%~di%%~piout
  117. echo %%i -^> %%~di%%~piout\%%~ni.%outputType% ^[!count!/%total%^]
  118. %inkscapePath% --batch-process --export-filename="%%~di%%~piout\%%~ni.%outputType%" --export-dpi=%dpi% "%%i"
  119. )
  120. ) else (
  121. :: Inkscape 0.9.x and older
  122. for /R %%i in (*.%sourceType%) do (
  123. set /a count=count+1
  124. echo %%i -^> %%~di%%~piout\%%~ni.%outputType% ^[!count!/%total%^]
  125. if "%outputType%" NEQ "%validOutput4%" (
  126. %inkscapePath% --without-gui --file="%%i" --export-%outputType%="%%~di%%~piout\%%~ni.%outputType%" --export-dpi=%dpi%
  127. ) else (
  128. if "%sourceType%" NEQ "pdf" (
  129. %inkscapePath% --without-gui --file="%%i" --export-pdf="%%~di%%~piout\%%~ni.pdf" --export-dpi=%dpi%
  130. )
  131. %inkscapePath% --without-gui -z -f "out\%%~ni.pdf" -l "%%~di%%~piout\%%~ni.%validOutput4%"
  132. if "%toDelOrNot%" EQU "y" (
  133. del "%%~ni.pdf" /f /q
  134. )
  135. )
  136. )
  137. )
  138. echo.
  139. echo %count% file(s) converted from %sourceType% to %outputType%! (Saved in out folder)
  140. echo.
  141. :end
  142. pause
 
 

3187

Inkscape batch convert (svg|pdf|eps|emf|wmf to eps|pdf|png|svg)

Batch convert files with a windows bat file
More Info: https://gist.github.com/JohannesDeml/779b29128cdd7f216ab5000466404f11

SVG Tool

Linhas
168
Palavras
620
Tamanho
4,8 KB
Criado
Revisões
4
Tipo
text/plain
MIT License (MIT)

Ligação

Por favor entre com a sua conta para deixar um comentário!