@echo off

setlocal EnableDelayedExpansion
set folder=%cd%
cd work\out


choice /C LSN /m "Use large (L), small (S) or no (N) lastpage  "
if %errorlevel%==1 (
set page=brought_to_you_by.pdf
) else if %errorlevel%==2 (
set page=brought_to_you_by_[TABLET].pdf
)

if NOT EXIST output mkdir output
set thumb=1

for %%i in (*.tif) DO (
convert %%i -resize 240x310^^! -quality 80%% "!folder!\%%~ni.jpg"
convert %%i "output\%%~ni.pdf"
pdftk "output\%%~ni.pdf" "D:\Retro-Work\%page%" cat output "output\_temp.pdf"
pdftk "output\_temp.pdf" update_info D:\Retro-Work\metadata2.txt output "%folder%\%%~ni.pdf"
del output\_temp.pdf /q

echo url: %%~ni.pdf > "%folder%\%%~ni.txt"
echo title: >> "%folder%\%%~ni.txt"
echo lang: English >> "%folder%\%%~ni.txt"

)
pause
