回复 55# ailier532
遍历批处理文件所在目录下所有文件夹,添加书签后合并,删除源文件、及添加书签后的文件、空文件夹。使用前先备份。
- @echo off
- chcp 65001 >nul
- rem 批处理保存为utf-8编码格式
- cd /d "%~dp0"
- rem 仅给无书签的pdf文件添加文件名作为书签(part) ,所有文件添加(all)
- set "c=all"
-
- for /d %%d in (*) do (
- if exist "%%d\*.pdf" (
- pushd "%%d"
- for /f "delims=" %%i in ('dir /b /a-d *.pdf') do (
- pdftk "%%i" dump_data_utf8 output >$
- setlocal
- if /i "%c%" equ "all" (
- call :1 "%%i"
- ) else if /i "%c%" equ "part" (
- find "BookmarkTitle:" <$ 1>nul || call :1 "%%i"
- )
- endlocal
- )
- pdftk *.pdf cat output "%~dp0%%~nxd.pdf"
- rem 删除pdf
- del *.pdf 2>nul
- del $;report.txt 2>nul
- popd
- rd "%%d" 2>nul
- )
- )
- pause & exit
-
- :1
- for /f "tokens=1* delims=[]" %%a in ('find /n "NumberOfPages: " ^<$') do (
- set #%%a=1
- )
- (for /f "tokens=1* delims=[]" %%a in ('find /n /v "" ^<$') do (
- echo=%%b
- if defined #%%a (
- echo BookmarkBegin
- echo BookmarkTitle: %~n1
- echo BookmarkLevel: 1
- echo BookmarkPageNumber: 1
- )
- ))>report.txt
- pdftk "%~1" update_info_utf8 report.txt output $.pdf
- move $.pdf "%~1"
- exit /b
复制代码
|