@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION :: Check Command Line IF "%~1"=="" GOTO Syntax IF NOT EXIST "%~1" GOTO InvalidPDF IF /I NOT "%~x1"==".pdf" GOTO InvalidPDF IF NOT "%~2"=="" GOTO Syntax :: 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 PUSHD "%~dp1" "%ProgFile%" -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r600x600 -sOutputFile="%~n1.%%d.jpg" "%~nx1" SET GSCommand= FOR %%A IN (%~n1.*.jpg) DO ( REM Make sure to append a trailing space after showpage SET GSCommand=!GSCommand! ^(%%A^) viewJPEG showpage ) "%ProgFile%" -dNOSAFER -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -o "%~n1.jpg.pdf" "%ProgDir%.\lib\viewjpeg.ps" -c "%GSCommand%" POPD ENDLOCAL GOTO:EOF :InvalidPDF ECHO. ECHO ERROR: Please specify a valid PDF file GOTO Syntax :FileExists ECHO. ECHO ERROR: The output file already exists. ECHO Move or rename %TextFile% and try again. GOTO Syntax :NoGhostScript ECHO. ECHO ERROR: GhostScript not found :Syntax ECHO. ECHO PDF2JPG2PDF.bat, Version 1.00 for Windows 10 ECHO Use GhostScript to convert a "text-based" PDF file to "image-based" PDF ECHO. ECHO Usage: %~nx0 "pdffile" ECHO. ECHO Where: pdffile is the PDF file to be converted ECHO. ECHO Notes: The resulting "image-based" PDF will be saved in the same folder ECHO under the same name as the "text-based" PDF, but with extension ECHO .jpg.pdf instead of .pdf ECHO This batch file requires GhostScript to convert PDF to 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