如何合并PDF文件(如果不可能,则合并PS),以使每个文件都从奇数页开始? [英] How can I merge PDF files (or PS if not possible) such that every file will begin in a odd page?
问题描述
我正在UNIX系统上工作,我想将成千上万个PDF文件合并到一个文件中以进行打印.我不知道他们提前多少页.
I am working on a UNIX system and I'd like to merge thousands of PDF files into one file in order to print it. I don't know how many pages they are in advance.
我想双面打印,这样两个文件将不在同一页面上.
I'd like to print it double sided, such that two files will not be on the same page.
因此,我希望合并文件对齐,以便每个文件都从奇数页开始,如果下一个要写入的位置是偶数页,则将添加一个空白页.
Therefore it I'd the merging file to be aligned such that every file will begin in odd page and a blank page will be added if the next place to write is an even page.
推荐答案
这是我使用的解决方案(它基于@Dingo的基本原理,但是使用了更简单的PDF操作方法):
Here's the solution I use (it's based on @Dingo's basic principle, but uses an easier approach for the PDF manipulation):
首先,我创建一个PDF文件,该文件的某处只有一个空白页,例如在"/path/to/blank.pdf"中.
First, I create a PDF file with a single blank page somewhere, e.g. in "/path/to/blank.pdf".
然后,从包含我所有pdf文件的目录中,运行一个小脚本,该脚本将blank.pdf文件附加到具有奇数页码的每个pdf中:
Then, from the directory that contains all my pdf files, I run a little script that appends the blank.pdf file to each pdf with an odd page number:
#!/bin/bash
for f in *.pdf; do
let npages=$(pdfinfo "$f"|grep 'Pages:'|awk '{print $2}')
let modulo="($npages %2)"
if [ $modulo -eq 1 ]; then
pdftk "$f" "/path/to/blank.pdf" output "aligned_$f"
else
cp "$f" "aligned_$f"
fi
done
现在,所有"aligned_"文件都具有偶数页码,我可以使用
Now, all "aligned_" files have even page numbers, and I can join them using
pdftk aligned_*.pdf output result.pdf
这篇关于如何合并PDF文件(如果不可能,则合并PS),以使每个文件都从奇数页开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!