Created
February 24, 2024 05:27
-
-
Save skpassegna/9a72151eaf6c670d3739f36fd6388929 to your computer and use it in GitHub Desktop.
This script will convert all SVG files in the current directory to PDF files using Inkscape. (Windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM Check if Inkscape is installed | |
if exist "%ProgramFiles%\Inkscape\bin\inkscape.exe" ( | |
set inkscape_path=%ProgramFiles%\Inkscape\bin\inkscape.exe | |
) else ( | |
echo Error: Inkscape not found. Please install it from https://inkscape.org/ | |
exit /b 1 | |
) | |
REM Set output folder (optional) | |
set output_folder= | |
REM Loop through all SVG files in the current directory | |
for %%a in (*.svg) do ( | |
REM Get the filename without extension | |
set filename=%%~na | |
REM Build the output filename (use output folder if specified) | |
if not "%output_folder%"=="" ( | |
set output_file=%output_folder%\%%filename.pdf | |
) else ( | |
set output_file=%%filename.pdf | |
) | |
REM Convert the SVG file to PDF using Inkscape | |
echo Converting "%%a" to "%output_file%"... | |
"%inkscape_path%" --export-type="pdf" --export-dpi=300 "%%a" -o "%output_file%" | |
REM Check for errors (optional) | |
if errorlevel 1 ( | |
echo Error: Failed to convert "%%a". | |
) | |
) | |
echo Done! | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Batch script for converting SVG files to PDF using Inkscape
This script will convert all SVG files in the current directory to PDF files using Inkscape. It includes detailed comments to explain each step.
Requirements:
Instructions:
.bat
file (e.g.,convert_svg_to_pdf.bat
) in the directory containing your SVG files.convert_svg_to_pdf.bat
).Explanation:
output_folder
variable to specify a different destination for the PDF files.for
loop iterates through all SVG files in the current directory.--export-type="pdf"
specifies the output format.--export-dpi=300
sets the output resolution to 300 DPI (you can adjust this)."%%a"
is the input SVG file.-o "%output_file%"
specifies the output PDF file.Alternative tools:
If you cannot use Inkscape or batch scripting, consider these alternative online tools.
I hope this helps!