ここには部分的なGNU makeと部分的なCの解決策があります。私は400ページの文書をチェックしたが、膨らんでいなかった。これが満足であれば、Cプログラムはシェルスクリプトとして書き直され、makefileに組み込まれます。
この問題は、pdftk
の正しいページ番号のシーケンスを生成することから成り立っています。私はそのシーケンスを生成するprint_order.cと呼ばれる小さな(< 70行)Cプログラムを書いています。そして、私はそれを使用するようにmakefile
を変更しました。
print_order.c
#include <stdio.h>
#include <stdlib.h>
int pg_eight [] = {1, 3, 5, 7, 4, 2, 8, 6};
const char* blank_page = "B1";
void advance_pg_eight()
{
int j=0;
for(j=0; j < 8; j++)
pg_eight[j] += 8;
}
void print_pg_eight (long int npages)
{
int j=0;
static int nprinted = 0;
for (j=0; j < 8 && nprinted < npages; j++) {
if(pg_eight[j] > npages)
printf("%4s ", blank_page);
else
{
printf("%4d ", pg_eight[j]);
nprinted++;
}
}
}
long int get_npages(const char *first_arg)
{
char *endptr = "Hello";
long int npages = strtol(first_arg, &endptr, 10);
if (*endptr != '\0' || npages <= 0)
return 0;
return npages;
}
int main (int argc, char* argv[])
{
long int npages = 0;
int neights = 0, j=0;
if (argc < 2) {
fprintf(stderr, "%s: Insufficient number of arguments\n", argv[0]);
return 0;
}
npages = get_npages(argv[1]);
if (0 == npages) {
fprintf(stderr, "%s: Failed to parse number of pages (%s)\n", argv[0], argv[1]);
return 0;
}
neights = npages/8;
if (npages % 8 != 0)
neights++;
for(j = 0; j < neights; j++) {
print_pg_eight(npages);
advance_pg_eight();
printf("\n");
}
printf("\n");
}
makefile
#
# use a shell escape to get the number of pages of the pdf file with:
# qpdf --show-npages ./cards.pdf
NPAGES := $(shell qpdf --show-npages ./cards.pdf)
#
PRINT := $(shell ./print_order $(NPAGES))
print.pdf: makefile cards.pdf blank.pdf print_order
pdftk B=blank.pdf cards.pdf cat $(PRINT) output print.pdf
print_order: print_order.c
91ページのprint_order
のサンプル出力日時:
1 3 5 7 4 2 8 6
9 11 13 15 12 10 16 14
17 19 21 23 20 18 24 22
25 27 29 31 28 26 32 30
33 35 37 39 36 34 40 38
41 43 45 47 44 42 48 46
49 51 53 55 52 50 56 54
57 59 61 63 60 58 64 62
65 67 69 71 68 66 72 70
73 75 77 79 76 74 80 78
81 83 85 87 84 82 88 86
89 91 B1 B1 B1 90
B1
は、最初のページが空白のpdfの最初のページです。このソリューションを使用するには
:blank.pdf
コピーcards.pdf
として再発注する必要がありPDFとして
print_order.c
コピー空白の最初のページでPDFを作成するためのCコード上記
- コピー
- 実行
make
希望します。
私はあなたの解決策を働かせようとしています。まず、print_orderを作成する指示がないようです: 'gcc print_order.c -o print_order' –
第二に、少なくとも私のマシンでは、' pdftk'コマンドを 'pdftk cards.pdf B = blank 'に再配置する必要があります。 pdf cat $(PRINT)出力print.pdf'。 これは、ハンドルのないページが最初の入力ファイルを参照するためです。 'pdftk'のヘルプから引用:ページ範囲からハンドルが省略された場合、ページは最初の入力PDFから取り出されます。 –
以外は正常に動作します。ありがとう –