Instantly share code, notes, and snippets.
CreatedFebruary 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 hidden or 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
@echooff | |
REM Check if Inkscape is installed | |
ifexist"%ProgramFiles%\Inkscape\bin\inkscape.exe" ( | |
setinkscape_path=%ProgramFiles%\Inkscape\bin\inkscape.exe | |
)else ( | |
echo Error: Inkscape not found. Please install it from https://inkscape.org/ | |
exit /b1 | |
) | |
REM Set output folder (optional) | |
setoutput_folder= | |
REM Loop through all SVG files in the current directory | |
for%%ain (*.svg)do ( | |
REM Get the filename without extension | |
setfilename=%%~na | |
REM Build the output filename (use output folder if specified) | |
ifnot"%output_folder%"=="" ( | |
setoutput_file=%output_folder%\%%filename.pdf | |
)else ( | |
setoutput_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) | |
iferrorlevel1 ( | |
echo Error: Failed to convert"%%a". | |
) | |
) | |
echo Done! | |
pause |
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:
- Inkscape installed:https://inkscape.org/
- Batch file execution enabled on your system
Instructions:
- Save the following code as a
.bat
file (e.g.,convert_svg_to_pdf.bat
) in the directory containing your SVG files. - Open a command prompt in the same directory.
- Run the batch file by typing its name and pressing Enter (e.g.,
convert_svg_to_pdf.bat
).
Explanation:
- The script first checks if Inkscape is installed and retrieves its path.
- You can optionally set an
output_folder
variable to specify a different destination for the PDF files. - The
for
loop iterates through all SVG files in the current directory. - For each file, the script generates the output filename and calls Inkscape with the appropriate commands:
--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.
- An optional error check is included to identify any conversion failures.
- The script prints a completion message and pauses the window.
Alternative tools:
If you cannot use Inkscape or batch scripting, consider these alternative online tools.
- Dedicated software: Adobe Illustrator, CorelDRAW, and other graphics software can also export SVG files to PDF.
I hope this helps!
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment