先从网上下载免费的 pdftk 命令行工具
官网 https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ 的安装版或者某些下载网站的绿色版都可以
先打开 Windows 的 Powershell
第一次使用需要开启 Powershell 执行策略,方法如下:
管理员运行 Powershell
执行命令 Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine
然后在 Powershell 中 cd 切换到到 pdftk 命令的目录
复制下面的脚本保存文件扩展名 ps1,例如为 test.ps1
修改下面脚本的 $pdfFile 中的 test.pdf 的值为 pdf 文件名(最好为英文)
$SetsOfPages 的值为要切分的页数
在 Powershell 中运行 .\test.ps1,然后查看输出过程和目录中新建的拆分后多个 pdf 文件吧
$pdfPath = '.\'
$pdfFile = Join-Path $pdfPath "test.pdf"
$SetsOfPages = 2
$Match = 'NumberOfPages: (\d+)'
$NumberOfPages = [regex]::match((.\pdftk $pdfFile dump_data),$Match).Groups[1].Value
"{0,2} pages in {1}" -f $NumberOfPages, $pdfFile
for ($Page=1;$Page -le $NumberOfPages;$Page+=$SetsOfPages){
$File = Get-Item $pdfFile
$Range = "{0}-{1}" -f $page,[math]::min($Page+$SetsOfPages-1,$NumberOfPages)
$OutFile = Join-Path $pdfPath ($File.BaseName+"_$Range.pdf")
"processing: {0}" -f $OutFile
.\pdftk $pdfFile cat $Range output $OutFile
}
参考 https://www.it1352.com/1619663.html ,本作者做了修改并测试成功