(view source code of jpgs2pdf.bat as plain text)
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:: Check Command Line
IF "%~1"=="" GOTO Syntax
SET PDFFile=""
SET GSCommand=
FOR %%A IN (%*) DO (
IF /I "%%~xA"==".jpg" (
IF NOT EXIST "%%~A" GOTO InvalidJPG
REM Make sure to append a trailing space after showpage
SET GSCommand=!GSCommand! ^(%%~A^) viewJPEG showpage
) ELSE IF /I "%%~xA"==".jpeg" (
IF NOT EXIST "%%~A" GOTO InvalidJPG
REM Make sure to append a trailing space after showpage
SET GSCommand=!GSCommand! ^(%%~A^) viewJPEG showpage
) ELSE IF /I "%%~xA"==".pdf" (
IF !PDFFile!=="" (
SET PDFFile="%%~A"
) ELSE (
GOTO OnePDFOnly
)
) ELSE (
GOTO Syntax
)
)
IF %PDFFile%=="" SET PDFFile="%~dpn1.pdf"
IF EXIST %PDFFile% GOTO FileExists
:: Find GhostScript executable
SET ProgDir=
SET ProgFile=
FOR /F "tokens=*" %%A IN ('REG.EXE Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f Ghostscript ^| FIND.EXE /I "HKEY_"') DO (
FOR /F "tokens=2*" %%B IN ('REG.EXE Query "%%~A" /v UninstallString') DO (
SET ProgDir=%%~dpC
)
)
IF "%ProgDir%"=="" GOTO NoGhostScript
FOR /F "tokens=*" %%A IN ('DIR /B /S "%ProgDir%gswin*c.exe"') DO SET ProgFile=%%~fA
IF "%ProgFile%"=="" GOTO NoGhostScript
:: Run GhostScript
"%ProgFile%" -dNOSAFER -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -o %PDFFile% "%ProgDir%lib\viewjpeg.ps" -c "%GSCommand%"
ENDLOCAL
GOTO:EOF
:InvalidJPG
ECHO.
ECHO ←[0;1;31mERROR:←[0m Please specify valid JPG files
GOTO Syntax
:OnePDFOnly
ECHO.
ECHO ←[0;1;31mERROR:←[0m Please specify no more than 1 PDF file
GOTO Syntax
:FileExists
ECHO.
ECHO ←[0;1;31mERROR:←[0m The output file already exists.
ECHO Move or rename %PDFFile% and try again.
GOTO Syntax
:NoGhostScript
ECHO.
ECHO ←[0;1;31mERROR:←[0m GhostScript not found
:Syntax
ECHO.
ECHO JPGs2PDF.bat, Version 1.00 for Windows 10
ECHO Use GhostScript to convert/merge JPG image(s) into a single PDF file
ECHO.
ECHO Usage: ←[0;1m%~nx0 "jpegfile" [ "jpegfile" [ .. ] ] [ "pdffile" ]←[0m
ECHO.
ECHO Where: ←[0;1mjpegfile←[0m JPG file(s) to be converted/merged into a single PDF file
ECHO ←[0;1mpdffile←[0m output PDF file (default: name and location of first JPG,
ECHO but with extension .pdf)
ECHO.
ECHO Notes: This batch file requires GhostScript to convert JPG to PDF.
ECHO GhostScript can be found at ←[0;1;30mhttps://www.ghostscript.com/←[0m
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
ENDLOCAL
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0077 seconds