(view source code of pdf2jpg2pdf.bat as plain text)
@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 ←[0;1;31mERROR:←[0m Please specify a valid PDF file
GOTO Syntax
:FileExists
ECHO.
ECHO ←[0;1;31mERROR:←[0m The output file already exists.
ECHO Move or rename %TextFile% and try again.
GOTO Syntax
:NoGhostScript
ECHO.
ECHO ←[0;1;31mERROR:←[0m 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: ←[0;1m%~nx0 "pdffile"←[0m
ECHO.
ECHO Where: ←[0;1mpdffile←[0m 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 ←[0;1m.jpg.pdf←[0m instead of ←[0;1m.pdf←[0m
ECHO This batch file requires GhostScript to convert PDF to 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.0050 seconds