本帖最后由 aloha20200628 于 2024-7-8 23:23 编辑
回复 5# qd2024
本帖的关键是pdftk.exe要求加入 ‘包含中文标签’ 的设置文件须为utf-8编码(无BOM头标),其文件名似乎还须是单字节ascii字符
以下代码存为test.bat,放在 *.pdf,标签.txt,pdftk.exe 等文件同在的目录下运行,先用 "标签.txt" 生成 "BMu8.txt" ,再将其转码为无头标utf-8,最后调用pdftk生成 "*.new.pdf" 即为楼主所要...
- <# ::
- @echo off &if not exist "*.pdf" (exit/b) else if not exist "标签.txt" exit/b
- powershell "iex(${%~f0}|out-string)" &if not exist "BMu8.txt" exit/b
- for %%F in (*.pdf) do (set "pF=%%F"&set "_pF=%%~nF.new.pdf")
- pdftk.exe "%pF%" update_info_utf8 "BMu8.txt" output "%_pF%"
- del "BMu8.txt"&pause&exit/b
- #>
- $n=1; $s=foreach($l in gc "标签.txt") {
- echo("BookmarkBegin`nBookmarkTitle: "+$l+"`nBookmarkLevel: 1`nBookmarkPageNumber: "+($n++))
- }; [io.file]::writeAlllines("BMu8.txt", $s); exit
复制代码
|