4

我想重新组合我的 PDF 文档以使用我的打印机中的 A4 格式在 A5 上打印它们。此外,我需要在每个 A5 页面上打印两个站点(幻灯片),当然应该是双面的。因此,A4 页面是横向格式。比我想在中间剪。9张幻灯片的简短示例:

first A4   first back    second A4
 [1][5]      [3][7]       [9][-]
 [2][6]      [4][8]       [-][-]

剪完后,我会在一张双面 A5 纸上放 1-4、5-8、9 幻灯片。

使用“小册子打印”打印此文件尚未奏效。我想过使用 pdftk 使用 shell 脚本自动重新组装 PDF 页面并计算 mod 8,因为手动更改顺序不是一种选择。重新安排订单后,我可以使用打印机的选项轻松打印幻灯片。

怎么可能做到这一点,或者有更简单的方法吗?谢谢

4

2 回答 2

5

据我了解,您正在尝试在每张 A4 肖像上放置4 页,这将给您 4 个A6单页(A4 页面为两张 A5 纸),因为将 A4 区域分成 4 个部分,意味着将每一边除以两个,所以我们将有:

29.7 厘米 /2 = 14.8 厘米(近似值)

21 厘米除以二 = 10.5 厘米

A4分为4部分

很明显,在同一个A4纵向区域,可以找到地方,4张A6纵向单页,2张A5横向A5页,如图:

A4 和 A5 分成 4 个部分

那么,您不想将小册子制作成 A6 格式,而只是将纵向 A4 切成两半来制作 A4 页面的 2 张 A5 纸吗?您是否不想进一步剪裁这些 A5 横向页面以装订 A6 小册子?

因为,据我所知,您似乎正在寻找一个脚本,该脚本能够制作一个小册子,为 A4 纸的每一面加上 4 个 A6 页,以正确的顺序重新计算拼版顺序,以获得正确的正面/背面匹配,看看我的剧本

注意:在开始之前,将您输入的多页 pdf(具有 A4 大小)调整为 A6

这可以在他的帮助下完成

多价.jar

java -cp path...to/Multivalent.jar tool.pdf.Impose -dim 1x1 -paper A6 input.pdf

然后获取生成的输出文件(记得处理副本)将其重命名为您的起始输入文件并使用此脚本

要执行此任务,并确保您的 pdf 多页文件具有执行拼版所需的正确页数(8 或 8 的整数倍),您将使用基于 pdftk 的脚本(至少 1.41 版本具有邮票功能和Multivalent.jar - https://rapidgator.net/file/c6bd7f31bf8885bcaa69b50ffab7e355/Multivalent20060102.jar.html(包含工具的最新免费版本)。

用法:namescript file.pdf multivalentpath

multivalentpath相对的:如果您将 Multivalent.jar 下载到您的家中,那么multivalentpath将是/home/。您还可以自定义脚本并直接替换第二个参数的值(多价路径,因此您不需要每次都键入多价路径;在这种情况下,替换multivalentpath=$2

multivalentpath=/home/Multivalent.jar

该脚本还将裁剪标记添加到最终输出 pdf

查看动画或生成的输出文件,并添加裁剪标记以轻松剪切两倍数量的纸张(首先是水平,然后是垂直)

结果输出文件

完成打印并将最后一张纸放在其他纸上后,查看最后一张拼版纸

要剪切的最后一页

这需要水平切割(我用虚线突出显示)一半,以便能够关闭两个系列的床单(上和下)彼此(上在下)从获得单系列床单两个原始系列的床单,

单张系列

在这个阶段,您可以进一步沿着虚线切割纸张,以便能够整理单张 A6 纸张并用胶水、夹子或其他方式粘合,或者使用两点订书机弯曲您制作的小册子

注意:您看到的空白页会自动放置在原始pdf的最后一页之后,正如您在问题中正确陈述的那样,它们需要执行正确的拼版顺序,它们不会干扰顺序逻辑顺序,在生成的装订小册子中,在我们的示例中,订单将是:

1,2,3,4,5,6,7,8,9, 10,11,1,2,13,14,15,16

粗体页,将留空,只需要执行正确的拼版,如果页数不是 8 的倍数,则无法执行

#!/bin/bash
#
#
############################
#
#      use: namescript file.pdf multivalentpath
#
############################
#
#
#
#
file=$1
multivalentpath=$2
pages="`pdftk $file dump_data | grep NumberOfPages | cut -d : -f2`"
echo $pages
halfpages="`echo -n $(( $pages / 2 ))`"
echo $halfpages
incr="$(echo "scale=0; $halfpages+1" |bc -l)"
dividedby4="$(echo "scale=0; $pages/8" |bc -l)"
lastupperpage="$(echo "scale=0; $pages-2" |bc -l)"
u="u"
#first case
h="$(pdfinfo $file | grep "Page size" | cut -d x -f1 | tr 'Page size:' ' ' | xargs)"
w="$(pdfinfo $file | grep "Page size" | cut -d x -f2  | tr 'pts' ' ' | xargs)"
echo $h
echo $w
doubleheight="$(echo "scale=0; $h * 2" |bc -l)"
doublewidth="$(echo "scale=0; $w * 2" |bc -l)"
echo $doubleheight
echo $doublewidth
if [ $(( $pages % 8 )) -eq 0 ]
then
echo " the file has already a number of pages multiple by eight"
sequence="$(for ((x=$halfpages, y=$incr, z=$pages, w=1;x>=4, y<=4, z>=2, w<=$lastupperpage;x--, y++, z--, w++)); do echo "$x$u $y$u;$z $w"; done | tr ";" "\n" | tr " " "," | awk -F "," '{ print $2 "," $1; getline; print; getline; print; getline; print $2 "," $1 }' | tr "\n" "," | cut -d "," -f 1-`seq -s, 1 $pages`)"
echo "sequence is $sequence"
java -cp "$multivalentpath"Multivalent.jar tool.pdf.Impose -verbose -dim 2x2 -paper "$doubleheight"x"$doublewidth"pt -layout "$sequence" $file
 
cat << EOF |uudecode
begin-base64 644 /tmp/grid.pdf
JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVy
IC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nFWPuw7CUAiGd56C2USEw+EUnsDZ
OhonbzHRwTr4+p5Wq20YgP//wuWBTFyQ+xiLwx1WbYOXJ+xQEhbcV/EIBV8g
eIWBxXYNSyfR5IIlXEkV7+CaSKz8lBtsIdydfAIFZyeTGbT7LslhjKIRhXJF
v20dSTJwg+CZKYWOPv+dJrNS9tEpVpTEP76lILfJHaYNk+TZHYJ9dBfIjRtF
/cQlSLH+SWzxy90JzgvYwBusBz89ZW5kc3RyZWFtCmVuZG9iago2IDAgb2Jq
CjE3OAplbmRvYmoKNCAwIG9iago8PC9UeXBlL1BhZ2UvTWVkaWFCb3ggWzAg
MCA1OTUgODQyXQovUGFyZW50IDMgMCBSCi9SZXNvdXJjZXM8PC9Qcm9jU2V0
Wy9QREZdCi9FeHRHU3RhdGUgOCAwIFIKPj4KL0NvbnRlbnRzIDUgMCBSCj4+
CmVuZG9iagozIDAgb2JqCjw8IC9UeXBlIC9QYWdlcyAvS2lkcyBbCjQgMCBS
Cl0gL0NvdW50IDEKPj4KZW5kb2JqCjEgMCBvYmoKPDwvVHlwZSAvQ2F0YWxv
ZyAvUGFnZXMgMyAwIFIKPj4KZW5kb2JqCjcgMCBvYmoKPDwvVHlwZS9FeHRH
U3RhdGUKL09QTSAxPj5lbmRvYmoKOCAwIG9iago8PC9SNwo3IDAgUj4+CmVu
ZG9iagoyIDAgb2JqCjw8L1Byb2R1Y2VyKEVTUCBHaG9zdHNjcmlwdCA4MTUu
MDQpCi9DcmVhdGlvbkRhdGUoRDoyMDEyMTIwMTIzNDMzNCkKL01vZERhdGUo
RDoyMDEyMTIwMTIzNDMzNCk+PmVuZG9iagp4cmVmCjAgOQowMDAwMDAwMDAw
IDY1NTM1IGYgCjAwMDAwMDA0NzIgMDAwMDAgbiAKMDAwMDAwMDU5MCAwMDAw
MCBuIAowMDAwMDAwNDEzIDAwMDAwIG4gCjAwMDAwMDAyODIgMDAwMDAgbiAK
MDAwMDAwMDAxNSAwMDAwMCBuIAowMDAwMDAwMjYzIDAwMDAwIG4gCjAwMDAw
MDA1MjAgMDAwMDAgbiAKMDAwMDAwMDU2MSAwMDAwMCBuIAp0cmFpbGVyCjw8
IC9TaXplIDkgL1Jvb3QgMSAwIFIgL0luZm8gMiAwIFIKL0lEIFso1xqpwgd/
HzDmRPwLQT3dEyko1xqpwgd/HzDmRPwLQT3dEyldCj4+CnN0YXJ0eHJlZgo3
MDEKJSVFT0YK
====
EOF
 
pdftk ${file%%.pdf}-up.pdf stamp /tmp/grid.pdf output gridded.pdf &&  mv gridded.pdf ${file%%.pdf}-up.pdf && echo "finished" && exit 0
else
echo "number of pages is not a multiple of 8, adding needed blank pages to complete the imposition sequence"
heightxwidth="`pdfinfo -box $file| grep MediaBox | cut -d : -f2 | awk '{print $3 FS $4}'`"
echo "%PDF-1.4
1 0 obj
<<
/CreationDate (D:20121202145344)
/Producer (text2pdf v1.1 (\251 Phil Smith, 1996))
/Title (blank.txt)
>>
endobj
2 0 obj
<<
/Type /Catalog
/Pages 3 0 R
>>
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Courier
>>
endobj
5 0 obj
<<
  /Font << /F1 4 0 R >>
  /ProcSet [ /PDF /Text ]
>>
endobj
6 0 obj
<<
/Type /Page
/Parent 3 0 R
/Resources 5 0 R
/Contents 7 0 R
>>
endobj
7 0 obj
<<
/Length 8 0 R
>>
stream
BT
/F1 10 Tf
1 0 0 1 50 798 Tm
12 TL
()'
ET
endstream
endobj
8 0 obj
44
endobj
3 0 obj
<<
/Type /Pages
/Count 1
/MediaBox [ 0 0 595 841 ]
/Kids [ 6 0 R ]
>>
endobj
xref
0 9
0000000000 65535 f 
0000000009 00000 n 
0000000132 00000 n 
0000000524 00000 n 
0000000181 00000 n 
0000000259 00000 n 
0000000330 00000 n 
0000000410 00000 n 
0000000506 00000 n 
trailer
<<
/Size 9
/Root 2 0 R
/Info 1 0 R
>>
startxref
609
%%EOF" | sed -e "s/595 841/$heightxwidth/g">/tmp/blank.pdf
fi
if [ $(( $pages / 8 )) -eq 0 ]
    then val0="`echo "scale=0; 8-$pages" | bc -l`"
else val1="`echo "scale=0; $pages/8" | bc -l`"; echo $val1
fi
if [ $(( $pages / 8 )) -eq 0 ] ; then echo "case 2: adding $val0 blank pages" ; sleep 1s && numpages=`for ((a=1; a <= $val0; a++)); do echo -n " B1 "; done` && pdftk A=$file B=/tmp/blank.pdf cat A $numpages output pagesadded.pdf && mv pagesadded.pdf $file
#new variable values for second case
unset pages
unset halfpages
unset incr
unset dividedby4
unset lastupperpage
pages="`pdftk $file dump_data | grep NumberOfPages | cut -d : -f2`"
halfpages="`echo -n $(( $pages / 2 ))`"
incr="$(echo "scale=0; $halfpages+1" |bc -l)"
dividedby4="$(echo "scale=0; $pages/8" |bc -l)"
lastupperpage="$(echo "scale=0; $pages-2" |bc -l)"
 
echo $pages
 
    else
val2="`let ADDITION=$val1+1; echo $ADDITION`"
val3="`let MULTIPLICATION=$val2*8; echo $MULTIPLICATION`"
val4="`echo "scale=0; $val3-$pages" |bc -l`"
echo " case 3: adding $val4 blank pages" ; sleep 1s
 
 
numpages="`for ((a=1; a <=  $val4; a++)); do echo -n " B1 "; done`"
echo $numpages
pdftk A=$file B=/tmp/blank.pdf cat A $numpages output pagesadded.pdf && mv pagesadded.pdf $file
fi
 
#new variable values for third case
unset pages
unset halfpages
unset incr
unset dividedby4
unset lastupperpage
pages="`pdftk $file dump_data | grep NumberOfPages | cut -d : -f2`"
halfpages="`echo -n $(( $pages / 2 ))`"
incr="$(echo "scale=0; $halfpages+1" |bc -l)"
dividedby4="$(echo "scale=0; $pages/8" |bc -l)"
lastupperpage="$(echo "scale=0; $pages-2" |bc -l)"
 
sequence="$(for ((x=$halfpages, y=$incr, z=$pages, w=1;x>=4, y<=4, z>=2, w<=$lastupperpage;x--, y++, z--, w++)); do echo "$x$u $y$u;$z $w"; done | tr ";" "\n" | tr " " "," | awk -F "," '{ print $2 "," $1; getline; print; getline; print; getline; print $2 "," $1 }' | tr "\n" ","  | cut -d "," -f 1-`seq -s, 1 $pages` | xargs)"
echo $sequence
java -cp "$multivalentpath"Multivalent.jar tool.pdf.Impose -verbose -dim 2x2 -paper "$doubleheight"x"$doublewidth"pt -layout "$sequence" $file
 
cat << EOF |uudecode
begin-base64 644 /tmp/grid.pdf
JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVy
IC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nFWPuw7CUAiGd56C2USEw+EUnsDZ
OhonbzHRwTr4+p5Wq20YgP//wuWBTFyQ+xiLwx1WbYOXJ+xQEhbcV/EIBV8g
eIWBxXYNSyfR5IIlXEkV7+CaSKz8lBtsIdydfAIFZyeTGbT7LslhjKIRhXJF
v20dSTJwg+CZKYWOPv+dJrNS9tEpVpTEP76lILfJHaYNk+TZHYJ9dBfIjRtF
/cQlSLH+SWzxy90JzgvYwBusBz89ZW5kc3RyZWFtCmVuZG9iago2IDAgb2Jq
CjE3OAplbmRvYmoKNCAwIG9iago8PC9U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o "finished 2"
exit 0
于 2013-06-26T14:49:20.397 回答
0

即使您问这个问题已经有一段时间了,您也可以尝试jPdf Tweak来安排您的(当前/未来)pdf 幻灯片。假设您的基本幻灯片打印为横向 A4,您最初要求的 n-up 布局的可能配置字符串将是
8:!+1N0.5+0.0%+100.0%,+5N0.5+100.0%+100.0%,+2N0.5+0.0%+0.0%,+6N0.5+100.0%+0.0%,!+3N0.5+0.0%+100.0%,+7N0.5+100.0%+100.0%,+4N0.5+0.0%+0.0%,+8N0.5+100.0%+0.0%
相应的布局(忽略此处的预设标题):
在此处输入图像描述

如果您从 postscript 文件开始,则可以将类似的字符串与pstops一起使用。

于 2013-10-27T21:42:31.513 回答