我发现这个问题很难表达,也找不到我想要做的事情的在线解决方案。
我知道如何使用以下脚本使用PDFTK将大型PDF拆分为单个页面:
pdftk your_file.pdf burst output your_directory/page_%02d.pdf但是现在我想将PDF除以另一页,这样每个新PDF都有两个(2)页(例如,第1+2页,第3+4页,5+ 6页等等)。
我知道Acrobat就像冠军一样,但是我需要一些我可以从Powershell执行的东西。
我对替代方案/解决办法持开放态度,比如在一页书破裂后,把它们合并成两页。
发布于 2017-05-06 17:33:24
这个PowerShell脚本将
更改前两个vars以适应您的环境。
## Q:\Test\2017\05\06\Split-Pdf.ps1
$pdfPath = 'Q:\Test\2017\05\06\'
$pdfFile = Join-Path $pdfPath "test.pdf"
$SetsOfPages = 3
$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
}编辑了,以处理页面的变量集,并正确处理挂起的问题。
再次编辑:找到了一个更简单的方法来缩短最后一组页面。
样本输出
> .\Split-Pdf.ps1
10 pages in Q:\Test\2017\05\06\test.pdf
processing: Q:\Test\2017\05\06\test_1-3.pdf
processing: Q:\Test\2017\05\06\test_4-6.pdf
processing: Q:\Test\2017\05\06\test_7-9.pdf
processing: Q:\Test\2017\05\06\test_10-10.pdf发布于 2017-05-07 09:33:42
发布于 2017-05-05 14:22:26
您可以使用cat关键字从所需的页面生成文件。
pdftk in.pdf cat 1-2 output out1.pdf
pdftk in.pdf cat 3-4 output out2.pdf为了更容易使用,可以添加bash脚本:
#!/bin/bash
COUNTER=0
while [ $COUNTER -lt $NUMBEROFPAGES ]; do
pdftk in.pdf cat $COUNTER-$COUNTER+1 output out1.pdf
let COUNTER=COUNTER+2
donehttps://stackoverflow.com/questions/43805726
复制相似问题