前提
mupdf-tools
pdftk
pdfjam
imagemagick
がインストールされている前提です.
手順別
2ページ1組になっているものを1ページ単位に分割する
Before
| ¦ | | ¦ |
| 1 ¦ 2 | | 3 ¦ 4 |
| ¦ | | ¦ |
After
| | | | | | | |
| 1 | | 2 | | 3 | | 4 |
| | | | | | | |
Command
mutool poster -x 2 in.pdf out.pdf
表紙用・裏表紙用に白紙を加える
4の倍数ページになるように調整する
Before
| | | | | | | |
| 1 | | 2 | | 3 | | 4 |
| | | | | | | |
After
| |
| - 1 |
| |
| | | | | | | |
| 1 | | 2 | | 3 | | 4 |
| | | | | | | |
| | | | | |
| + 1 | | + 2 | | + 3 |
| | | | | |
Command
convert xc:none -page A5 /tmp/blank.pdf
N=$(pdftk in.pdf dump_data | grep NumberOfPages | awk '{print $2}')
N=$(( (4 - (N + 2) % 4) % 4 + 1 ))
pdftk A=/tmp/blank.pdf B=in.pdf cat $(
printf 'A1 B1-end '
printf 'A1 %.0s' {1..$N}
) output out.pdf
rm /tmp/blank.pdf
- 必ずブランクページのサイズは他のページに合わせる.ここではA4を2分割する例と仮定して,A5に設定している.
- もしページサイズにばらつきがある場合,何らかの手段でページサイズを統一しておく.
ページサイズにばらつきがある場合の対処法
GhostScriptを使う
gs
コマンドのインストールが必要です.
gs -sOutputFile=out.pdf -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dPDFFitPage -dNOPAUSE -dBATCH in.pdf
プリンタユーティリティのPDF出力機能を使う
Macだとこういうのありますよね.
両面印刷・中とじ用に並び替えて2ページ1組に結合する
Before
| | | | | | | |
| - 1 | | 1 | | 2 | | 3 |
| | | | | | | |
| | | | | | | |
| 4 | | + 1 | | + 2 | | + 3 |
| | | | | | | |
After
| ¦ | | ¦ |
| + 3 ¦ - 1 | | 1 ¦ + 2 |
| ¦ | | ¦ |
| ¦ | | ¦ |
| + 1 ¦ 2 | | 3 ¦ 4 |
| ¦ | | ¦ |
Command (長辺とじ印刷の場合)
pdfbook in.pdf --outfile out.pdf
Command (短辺とじ印刷の場合)
pdfbook --short-edge in.pdf --outfile out.pdf
一気に実行
Before
| ¦ | | ¦ |
| 1 ¦ 2 | | 3 ¦ 4 |
| ¦ | | ¦ |
After
| ¦ | | ¦ |
| + 3 ¦ - 1 | | 1 ¦ + 2 |
| ¦ | | ¦ |
| ¦ | | ¦ |
| + 1 ¦ 2 | | 3 ¦ 4 |
| ¦ | | ¦ |
Command (長辺とじ印刷の場合)
convert xc:none -page A5 /tmp/blank.pdf
mutool poster -x 2 in.pdf /tmp/tmp-0.pdf
N=$(pdftk /tmp/tmp-0.pdf dump_data | grep NumberOfPages | awk '{print $2}')
N=$(( (4 - (N + 2) % 4) % 4 + 1 ))
pdftk A=/tmp/blank.pdf B=/tmp/tmp-0.pdf cat $(
printf 'A1 B1-end '
printf 'A1 %.0s' {1..$N}
) output /tmp/tmp-1.pdf
pdfbook /tmp/tmp-1.pdf --outfile out.pdf
rm /tmp/blank.pdf /tmp/tmp-*.pdf
Command (短辺とじ印刷の場合)
convert xc:none -page A5 /tmp/blank.pdf
mutool poster -x 2 in.pdf /tmp/tmp-0.pdf
N=$(pdftk /tmp/tmp-0.pdf dump_data | grep NumberOfPages | awk '{print $2}')
N=$(( (4 - (N + 2) % 4) % 4 + 1 ))
pdftk A=/tmp/blank.pdf B=/tmp/tmp-0.pdf cat $(
printf 'A1 B1-end '
printf 'A1 %.0s' {1..$N}
) output /tmp/tmp-1.pdf
pdfbook --short-edge /tmp/tmp-1.pdf --outfile out.pdf
rm /tmp/blank.pdf /tmp/tmp-*.pdf