@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 ERROR: Please specify valid JPG files GOTO Syntax :OnePDFOnly ECHO. ECHO ERROR: Please specify no more than 1 PDF file GOTO Syntax :FileExists ECHO. ECHO ERROR: The output file already exists. ECHO Move or rename %PDFFile% and try again. GOTO Syntax :NoGhostScript ECHO. ECHO ERROR: 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: %~nx0 "jpegfile" [ "jpegfile" [ .. ] ] [ "pdffile" ] ECHO. ECHO Where: jpegfile JPG file(s) to be converted/merged into a single PDF file ECHO pdffile 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 https://www.ghostscript.com/ ECHO. ECHO Written by Rob van der Woude ECHO https://www.robvanderwoude.com ENDLOCAL EXIT /B 1