Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for mergepdfs.bat

(view source code of mergepdfs.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. :: At least 3 files must be specified: 2 to merge, 1 target file
  5. IF "%~3"=="" GOTO Syntax
  6. :: Check if the PDF ToolKit is available
  7. PDFTK.EXE >NUL 2>&1 || GOTO Syntax
  8.  
  9.  
  10. SETLOCAL ENABLEDELAYEDEXPANSION
  11. SET InputFiles=
  12. :: All except the last argument are considered to be PDF input files
  13. :Loop
  14. IF /I NOT "%~x1"==".pdf" (
  15. 	ENDLOCAL
  16. 	GOTO Syntax
  17. )
  18. IF "%~2"=="" (
  19. 	SET OutputFile="%~1"
  20. ) ELSE (
  21. 	SET InputFiles=!InputFiles! "%~1"
  22. 	SHIFT
  23. 	GOTO Loop
  24. )
  25. PDFTK.EXE %InputFiles% cat output %OutputFile%
  26. ENDLOCAL
  27. GOTO:EOF
  28.  
  29.  
  30. :Syntax
  31. ECHO.
  32. ECHO MergPDFs.bat, Version 1.00
  33. ECHO Merge 2 or more PDF files into a single new PDF file
  34. ECHO.
  35. ECHO Usage:  MERGEPDFS  input1.pdf  input2.pdf  [ input3.pdf [ ... ] ]  output.pdf
  36. ECHO.
  37. ECHO Notes:  PDFs will be merged in the specified order.
  38. ECHO         This batch file requires PDFLabs' PDF Tool Kit (PDFTK),
  39. ECHO         available at http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
  40. ECHO         Whereas PDFTK has the option to select specific pages of the PDFs to
  41. ECHO         be merged, this wrapper batch file will always merge the entire file.
  42. ECHO         Existing target files will be overwritten, no questions asked.
  43. ECHO.
  44. ECHO Written by Rob van der Woude
  45. ECHO http://www.robvanderwoude.com
  46.  
  47. IF "%OS%"=="Windows_NT" EXIT /B 1
  48.  

page last modified: 2024-04-16; loaded in 0.0174 seconds