按照自定义订单自动将4个pdf页面放入A4纸张中

时间:2013-06-26 11:39:12

标签: pdf pdftk imposition

我想重新组装我的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,因为手动更改顺序不是一个选项。在我重新安排订单后,我可以使用打印机的选项轻松打印幻灯片。

如何做到这一点还是有更简单的方法呢? 感谢

2 个答案:

答案 0 :(得分:4)

据我所知,你试图在每张A4画像上强加 4页,这将给你4个 A6 单页(两张A5张对于A4页面)因为将A4区域分成4个部分,意味着将每一面分成两部分,所以我们将:

  

29.7 cm / 2 = 14.8 cm (近似值)

     

21 cm除以2 = 10.5 cm

A4 divided in 4 parts

很明显,那就是在同一个A4人像区域,可以找到地方,4个A6人像单页,2个A5风景A5页面,如图片所示:

A4 divided in 4 parts with A5

所以,您不希望能够将小册子制作成A6格式,而只是将A4纵向切成两半以制作A4页面的2张A5纸张吗?你是否有兴趣进一步削减这些A5景观页面以获得A6小册子?

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

  

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

这可以在他帮助

的情况下完成

Multivalent.jar

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

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

执行此任务,并确保您的pdf多页文件具有执行拼版所需的正确页数(8或8的整数倍),您将使用基于pdftk的此脚本(至少1.41)具有标记功能和 Multivalent.jar 的版本 - http://ge.tt/6fVll5H(包含工具的最新免费版本)。

  

用法:namescript file.pdf 多元路径

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

multivalentpath=/home/Multivalent.jar

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

查看添加了裁剪标记的动画或结果输出文件,以便轻松切割两张纸张数量(水平首先和垂直方向)

resulting output file

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

last page to cut

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

single sheet series

在这个阶段,您可以按照虚线进一步剪切单张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
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 2"
exit 0

答案 1 :(得分: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%
相应的布局看起来像(在此忽略预设标题):
enter image description here

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