gpt4 book ai didi

pdf - 按照自定义顺序自动将 4 个 pdf 页面拼成 A4 纸

转载 作者:行者123 更新时间:2023-12-04 17:21:13 27 4
gpt4 key购买 nike

我想重新组合我的 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页在每张肖像 A4 上,会给你 4 A6 单页(A4 页的两张 A5 纸)因为将 A4 区域分成 4 部分,意味着将每边一分为二,所以我们将有:

29.7 cm /2 = 14.8 cm (approximated)

21 cm divided by two = 10.5 cm


A4 divided in 4 parts
很明显,那么,在同一个A4纵向区域中,可以找到位置,4张A6纵向单页和2张A5横向A5页面,如图:
A4 divided in 4 parts with A5
所以,你不想把小册子做成A6格式,只想把纵向A4切成两半来制作2张A4页的A5纸?您是否不想进一步剪切这些 A5 横向页面以装订 A6 小册子?
因为,据我所知,您似乎正在寻找能够制作小册子的脚本,该小册子为 A4 纸的每一面拼版 4 个 A6 页,以正确的顺序重新计算拼版顺序,以获得正确的正面/背面匹配,看看我的脚本

note: before to start, resize to A6 your input multipage pdf (that has A4 size)


这可以在他的帮助下完成
Multivalent.jar
  • https://rapidgator.net/file/c6bd7f31bf8885bcaa69b50ffab7e355/Multivalent20060102.jar.html
    (包含工具的最新免费版本)

  • 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/c6bd7f31bf8885bcaa69b50ffab7e3506.html200jar
    (包含工具的最新免费版本)。

    usage: namescript file.pdf multivalentpath


    多价路径 亲戚 : 如果您将 Multivalent.jar 下载到您的家中,则 多价路径 将是 /home/ .您还可以自定义脚本并直接替换第二个参数的值(多价路径,因此您不需要每次都输入多价路径;在这种情况下,将 multivalentpath=$2 替换为 multivalentpath=/home/Multivalent.jar该脚本还将裁剪标记添加到最终输出 pdf
  • 9页pdf样本
  • http://ge.tt/7smk7Lk/v/1
  • 结果文件
  • http://ge.tt/7smk7Lk/v/2

  • 查看添加了裁剪标记的动画或生成的输出文件,以便轻松地将纸张数量减少两倍(先水平再垂直)
    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
    JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9M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wIG4gCjAwMDAwMDAyODIgMDAwMDAgbiAK
    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

    关于pdf - 按照自定义顺序自动将 4 个 pdf 页面拼成 A4 纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17319006/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com