Board logo

标题: [文件操作] [已解决]批处理如何按文件名合并PDF [打印本页]

作者: 嘛日去跳溪    时间: 2023-3-20 13:47     标题: [已解决]批处理如何按文件名合并PDF

本帖最后由 嘛日去跳溪 于 2023-3-20 19:06 编辑

如现在有文件
A1.1-1_1.pdf
A1.1-1_2.pdf
A1.1-1_3.pdf
A1.1-2_1.pdf
A1.1-2_2.pdf
A1.1-2_3.pdf
A1.1-2_4.pdf
...
A1.1-1000_1.pdf
A1.1-1000_2.pdf
A1.1-1000_3.pdf
A1.1-1000_4.pdf
按名称合并成A1.1-1.pdf、A1.1-2.pdf...A1.1-1000.pdf
作者: Batcher    时间: 2023-3-20 14:54

回复 1# 嘛日去跳溪


请参考Q-04把bat文件保存为ANSI编码:
https://mp.weixin.qq.com/s/Koje4FufWxWBs7ioDy_LJA
  1. @echo off
  2. REM 1. 下载并安装命令行工具 PDFtk Server
  3. REM https://www.pdflabs.com/tools/pdftk-server/
  4. REM 2. 请根据自己电脑实际情况设置该路径
  5. set "path=C:\Program Files (x86)\PDFtk Server\bin;%path%"
  6. cd /d "%~dp0"
  7. for /f "tokens=1* delims=_" %%i in ('dir /b /a-d *_*.pdf') do (
  8.     echo 正在处理文件:%%i===%%j
  9.     if not exist %%i.pdf (
  10.         pdftk %%i_*.pdf cat output %%i.pdf
  11.     )
  12. )
  13. pause
复制代码

作者: 嘛日去跳溪    时间: 2023-3-20 16:20

回复 2# Batcher


        有个问题,当同一个序号的文件数大于10个的时候,会按1、11、12这样排下去而不是1、2、3这样排
作者: Batcher    时间: 2023-3-20 16:24

回复 3# 嘛日去跳溪


    同一个序号的文件数最大是多少,会超过99吗?
作者: 嘛日去跳溪    时间: 2023-3-20 16:30

回复 4# Batcher


    不超
作者: Batcher    时间: 2023-3-20 17:27

回复 3# 嘛日去跳溪
  1. @echo off
  2. REM 1. 下载并安装命令行工具 PDFtk Server
  3. REM https://www.pdflabs.com/tools/pdftk-server/
  4. REM 2. 请根据自己电脑实际情况设置该路径
  5. set "path=C:\Program Files (x86)\PDFtk Server\bin;%path%"
  6. cd /d "%~dp0"
  7. for /f "tokens=1* delims=_" %%i in ('dir /b /a-d *_*.pdf ^| findstr "_[1-9].pdf"') do (
  8.     ren "%%i_%%j" "%%i_0%%j"
  9. )
  10. for /f "tokens=1* delims=_" %%i in ('dir /b /a-d *_*.pdf') do (
  11.     echo 正在处理文件:%%i===%%j
  12.     if not exist %%i.pdf (
  13.         pdftk %%i_*.pdf cat output %%i.pdf
  14.     )
  15. )
  16. pause
复制代码

作者: 嘛日去跳溪    时间: 2023-3-20 19:05

好了,谢谢,完美解决问题




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2