Automatically overlays 4 PDF pages onto A4 sheet following a special order

I want to collect my documents in PDF format so that I can print them on the A5 using A4 format from my printer. I also need to print two sites (slides) on each A5 page, which, of course, should be two-sided. Consequently, the A4 page is in landscape format. Than I want to cut it in the middle. A brief example for 9 slides:

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

After cutting, this will give me slides 1-4, 5-8, 9 on A5 double-sided paper.

Printing this option with Booklet Printing has not yet worked. I was thinking about automatically linking PDF pages using a shell script using pdftk and computing mod 8 since manually reordering is not an option. After I reordered, I can easily print slides using my printer settings.

How can this be done or is there an easier way? Thanks

+4
source share
2 answers

Although it has been a while since you asked this question, you can try jPdf Tweak to organize your (current / future) pdf slides. Suppose your base slides are printed as an A4 album, the possible configuration line for the desired layout you originally asked for would be
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%
the corresponding layout looks like (ignore the predefined header here):
enter image description here

If you start with postscript files, you can use a similar line with pstops.

0
source

As far as I understand, you are trying to overlay 4 pages on each A4 portrait, which will give you 4 A6 pages (two A5 sheets for an A4 page), since dividing the A4 area into 4 parts means dividing each side into two parts, so we will have :

29.7 cm / 2 = 14.8 cm (approximately)

21 cm divided by two = 10.5 cm

A4 divided in 4 parts

it is obvious that in the same area of โ€‹โ€‹the A4 book format you can find a place, 4 single-page A6 pages and two A5-pages A5, as in the picture:

A4 divided in 4 parts with A5

So, you donโ€™t want to make an A6 booklet, but only to cut the A4 portrait by half to create 2 A5 sheets for an A4 page? Are you not interested in shortening these A5 landscape pages to link the A6 booklet?

Since, as I understand it, it seems to you that you are looking for a script that can create a booklet overlaying 4 A6 pages for each side of A4 sheet, recounting the overlay sequence in the correct order to have the right front / back match, take a look at my script

note: before starting, resize to A6 to your input multi-page pdf (A4 size)

this can be done with

Multivalent.jar

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

then take the resulting output file (don't forget to work with the copy) rename it to the original input file and use this script

to accomplish this task and to ensure that your multi-page pdf file has the right number of pages needed to perform the overlay (8 or an integer multiple of 8), you will use this script based on pdftk (at less than 1.41 version with print and Multivalent.jar - - http://ge.tt/6fVll5H (latest free version with tools included).

use: namescript file.pdf multi-valued path

the ambiguous path is relative : if you downloaded Multivalent.jar to your home, the ambiguous path will be / home / . You can also configure the script and immediately replace the value for the second argument (multivalent path, so you do not need to enter the multivalent path every time, in this case replace multivalentpath=$2 with

multivalentpath=/home/Multivalent.jar

the script will also add crop marks to the final pdf output

viewing the animation or the resulting output file with the added crop marks to simplify cutting twice the number of sheets (first horizontally and vertically)

resulting output file

as soon as you finish typing and place the last sheet on other sheets, look at your last superimposed sheet

last page to cut

this need to be cut off (I selected with a dashed line) halfway horizontally to close two series of sheets (up and down) with each other (upper part lower), getting a single series of sheets from two original rows of sheets,

single sheet series

at this stage, you can additionally cut the sheet along the dotted line to be able to match the individual sheets of A6 and expecting with the help of glue, a clip or another, or using two points of a stapler, the bend of the booklet that you created

Note: the blank pages that you saw are automatically placed after the last written page of your original pdf, they are necessary, as you correctly said in your question, to perform the correct overlay sequence, they do not interfere with the logical sequence in the resulting booklet-bound order, in our example would be:

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

pages in bold will be left blank and necessary only for proper overlay, which cannot be done if the number of pages is not a multiple of 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 -dx -f1 | tr 'Page size:' ' ' | xargs)" w="$(pdfinfo $file | grep "Page size" | cut -dx -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 
+4
source

Source: https://habr.com/ru/post/1488269/


All Articles