I need to group multiple PDFs with the same order number (which is shown in the PDF filenames) into a new PDF. The new grouped PDF should have a new name= only the order number. The best solution is using a Windows bat file and GhostScript.
I have written a script, but it doesn't work, and I can't figure out why. The bat file "grouping.bat" is in the same folder as the PDFs.
@echo off
setlocal
rem Set the output directory
set "outputdir=%~dp0"
rem Get the current directory where the batch file is located
set "inputfolder=%~dp0"
rem Loop through the PDF files in the input folder
for %%F in ("%inputfolder%\*.pdf") do (
rem Extract the file name without extension
set "filename=%%~nF"
rem Get characters from position 16 to 22 of the file name
set "characters=!filename:~15,7!"
rem Set the output file path
set "outputfile=%outputdir%\%characters%.pdf"
gswin64c -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="%outputfile%" "%%F""
pause
)
echo PDF files combined successfully.
endlocal
Somehow it doesn't get the part of the file name. Can you guys help me find out why the code is not working?
ps:
- Ghostscript is installed on the win10 computer and settings in the environment (PATH) are working well.
- The PDF file names are structured as follows: "RAWRenderingDoc-976866-84.pdf".