Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@skpassegna
CreatedFebruary 24, 2024 05:27
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist
    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)
    @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
    @skpassegna
    Copy link
    Author

    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:

    1. Save the following code as a.bat file (e.g.,convert_svg_to_pdf.bat) in the directory containing your SVG files.
    2. Open a command prompt in the same directory.
    3. 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 anoutput_folder variable to specify a different destination for the PDF files.
    • Thefor 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

    [8]ページ先頭

    ©2009-2025 Movatter.jp