(view source code of mergepdfs.bat as plain text)
@ECHO OFF
:: Check Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: At least 3 files must be specified: 2 to merge, 1 target file
IF "%~3"=="" GOTO Syntax
:: Check if the PDF ToolKit is available
PDFTK.EXE >NUL 2>&1 || GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
SET InputFiles=
:: All except the last argument are considered to be PDF input files
:Loop
IF /I NOT "%~x1"==".pdf" (
ENDLOCAL
GOTO Syntax
)
IF "%~2"=="" (
SET OutputFile="%~1"
) ELSE (
SET InputFiles=!InputFiles! "%~1"
SHIFT
GOTO Loop
)
PDFTK.EXE %InputFiles% cat output %OutputFile%
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO MergPDFs.bat, Version 1.00
ECHO Merge 2 or more PDF files into a single new PDF file
ECHO.
ECHO Usage: MERGEPDFS input1.pdf input2.pdf [ input3.pdf [ ... ] ] output.pdf
ECHO.
ECHO Notes: PDFs will be merged in the specified order.
ECHO This batch file requires PDFLabs' PDF Tool Kit (PDFTK),
ECHO available at http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
ECHO Whereas PDFTK has the option to select specific pages of the PDFs to
ECHO be merged, this wrapper batch file will always merge the entire file.
ECHO Existing target files will be overwritten, no questions asked.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" EXIT /B 1
page last modified: 2023-03-10