<divclass="cardback"><DOCUMENT_FRAGMENT><divclass="mw-parser-output"><divclass="thumb tright"><divclass="thumbinner"style="width:152px;"><aclass="image"href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/c/c6/Anatomy_of_Reprinting_diagram.jpeg/720px-Anatomy_of_Reprinting_diagram.jpeg"><imgalt=""class="thumbimage"decoding="async"src="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/c/c6/Anatomy_of_Reprinting_diagram.jpeg/320px-Anatomy_of_Reprinting_diagram.jpeg"></a><divclass="thumbcaption"><divclass="magnify"><aclass="internal"href="File:Anatomy_of_Reprinting_diagram.jpeg.html"title="Enlarge"></a></div>(clockwise from top left): imposition from a single-page PDF into a booklet, anatomy of a book, a spread</div></div></div>
<liclass="toclevel-2"><ahref="#PDF_imposition_from_scratch"><spanclass="tocnumber">1.1</span><spanclass="toctext">PDF imposition from scratch</span></a></li>
<liclass="toclevel-1"><ahref="#booklet.sh_for_PDF_imposition_into_a_booklet"><spanclass="tocnumber">2</span><spanclass="toctext">booklet.sh for PDF imposition into a booklet</span></a></li>
</p><p>The aim is to write a Python script to automate the process by iterating recursively over pages in a PDF. These will be called in Python as subprocesses using the subprocess module.
</p>
<h3><spanclass="mw-headline"id="PDF_imposition_from_scratch">PDF imposition from scratch</span><spanclass="mw-editsection"><spanclass="mw-editsection-bracket">[</span><ahref="/mw-mediadesign/index.php?title=User:Simon/Trim4/PDF_imposition&action=edit&section=T-2"title="Edit section: ">edit</a><spanclass="mw-editsection-bracket">]</span></span></h3>
<p><b>23.09.19</b><br>
I'm working out which commands to use from the command line. The process should be as follows:<br>
</p>
<pre> #burst the source PDF, keep the name of the source plus page number (-%d)
</p><p>To identify the size of a single burst page in pixels, this is the command I used:
</p>
<pre> $ identify Carrier_burst-1.pdf
</pre>
<p>which returns this information:
</p>
<pre> Carrier_burst-1.pdf PDF 398x591 398x591+0+0 16-bit sRGB 19486B 0.000u 0:00.009
</pre>
<p><b>26.09.19</b><br>
Then for the next step, resizing each page to fit 2-up on an A4. It's easy enough to reduce to 50% if the original is A4, but in other formats it's a bit trickier...
</p>
<pre> #resize the resulting burst single page PDF (this only does one - needs Python loop to iterate recursively)
$ magick mogrify -resize 50% new_source.pdf
#or to resize to specific pixel dimensions such as 256x256
$ magick mogrify -resize 256x256 new_source.pdf
</pre>
<p>After resizing to 50%, the identify command returns these values:
</p>
<pre> Carrier_burst-1.pdf PDF 199x296 199x296+0+0 16-bit sRGB 51910B 0.000u 0:00.000
</pre>
<p><b>27.09.19</b><br>
The next steps are these:
</p>
<pre> #impose 2up on a page using imagemagick montage command
<p><aclass="external text"href="https://pypi.org/project/pdfimpose/"rel="nofollow">pdfimpose</a> is a python library that does imposition. It's quite easy and powerful, though again it is not quite set up for cutting pages. I found some Python code, which creates an imposed PDF in a 2x2 format, with folds to be made first vertically, then horizontally:
</p>
<pre> from pdfimpose import impose, VERTICAL, HORIZONTAL
</p><p><aclass="image"href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/1/1c/E_r_2x2_imposed.png/720px-E_r_2x2_imposed.png"><imgalt="E r 2x2 imposed.png"decoding="async"src="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/1/1c/E_r_2x2_imposed.png/320px-E_r_2x2_imposed.png"></a>
<h2><spanclass="mw-headline"id="booklet.sh_for_PDF_imposition_into_a_booklet">booklet.sh for PDF imposition into a booklet</span><spanclass="mw-editsection"><spanclass="mw-editsection-bracket">[</span><ahref="/mw-mediadesign/index.php?title=User:Simon/Trim4/Michaels_booklet_script_for_PDF_imposition&action=edit&section=T-1"title="Edit section: ">edit</a><spanclass="mw-editsection-bracket">]</span></span></h2>
<p>I found another way to do imposition using a script Michael wrote called booklet.sh, downloadable here: <aclass="external free"href="https://git.xpub.nl/murtaugh/95layouts"rel="nofollow">https://git.xpub.nl/murtaugh/95layouts</a><br>
It's a shell script that can run in the bin folder from the home directory, which allows you to run it wherever you are in the computer - you don't have to <code>cd</code> to the folder where the script is. To enable this, first you have to echo the path for the bin folder that the scripts are in. The command to run it from the terminal is:
</p>
<pre>booklet.sh source.pdf
</pre>
<p>It needs a few dependencies to run (mainly psutils).
</p>
<ol><li>Requirements: psutils, pdftk, python3 with reportlab (make_blank_pdf.py)</li></ol>
<pre>input=$1
base=${input%.*}
echo converting $input to $base.booklet.pdf
pdftk_utils.py $input pad --multiple 4 --output $base.01.pdf
<p>Note: Comment out or delete the last line to produce three .ps files - the first one is the source PDF, the second is the PDF imposed in the correct order, the third one is the imposed PDF pages on an A4 page. This works well if all you want to do is impose, print and fold. For cutting sheets you need to position the pages 2-up, centred on the page, which I can't quite figure out how to do...