You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
9.3 KiB
HTML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tasks of the Contingent Librarian</title>
<link rel="stylesheet" type="text/css" href="tasks.css">
<script src="tasks.js"></script>
</head>
<body>
<div class="cardback"><DOCUMENT_FRAGMENT><div class="mw-parser-output"><div class="thumb tright"><div class="thumbinner" style="width:152px;"><a class="image" href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/c/c6/Anatomy_of_Reprinting_diagram.jpeg/960px-Anatomy_of_Reprinting_diagram.jpeg"><img alt="" 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> <div class="thumbcaption"><div class="magnify"><a class="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>
<div class="toc" id="toc"><input class="toctogglecheckbox" id="toctogglecheckbox" role="button" style="display:none" type="checkbox"><div class="toctitle" dir="ltr" lang="en"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1"><a href="#PDF_imposition"><span class="tocnumber">1</span> <span class="toctext">PDF imposition</span></a>
<ul>
<li class="toclevel-2"><a href="#PDF_imposition_from_scratch"><span class="tocnumber">1.1</span> <span class="toctext">PDF imposition from scratch</span></a></li>
<li class="toclevel-2"><a href="#Using_pdfimpose"><span class="tocnumber">1.2</span> <span class="toctext">Using pdfimpose</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="#booklet.sh_for_PDF_imposition_into_a_booklet"><span class="tocnumber">2</span> <span class="toctext">booklet.sh for PDF imposition into a booklet</span></a></li>
</ul>
</div>
<h2><span class="mw-headline" id="PDF_imposition">PDF imposition</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/mw-mediadesign/index.php?title=User:Simon/Trim4/PDF_imposition&amp;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Premise: I will write my own script(s) to impose pages from a source PDF:<br>
</p><p><a class="image" href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/3/3e/Impose_01.jpg/960px-Impose_01.jpg"><img alt="Impose 01.jpg" decoding="async" src="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/3/3e/Impose_01.jpg/320px-Impose_01.jpg"></a><br>
</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><span class="mw-headline" id="PDF_imposition_from_scratch">PDF imposition from scratch</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/mw-mediadesign/index.php?title=User:Simon/Trim4/PDF_imposition&amp;action=edit&amp;section=T-2" title="Edit section: ">edit</a><span class="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)
$ pdftk source.pdf burst output source-%d.pdf
</pre>
<p>Results:<br>
<a class="image" href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/8/8d/Burst_01.png/960px-Burst_01.png"><img alt="Burst 01.png" decoding="async" src="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/8/8d/Burst_01.png/320px-Burst_01.png"></a>
<a class="image" href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/e/e4/Burst_02.png/960px-Burst_02.png"><img alt="Burst 02.png" decoding="async" src="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/e/e4/Burst_02.png/320px-Burst_02.png"></a>
</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
#assemble imposed PDFs into a single file
</pre>
<h3><span class="mw-headline" id="Using_pdfimpose">Using pdfimpose</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/mw-mediadesign/index.php?title=User:Simon/Trim4/PDF_imposition&amp;action=edit&amp;section=T-3" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p><a class="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
impose(inname=["foo.pdf"],outname="foo-impose.pdf",fold=[VERTICAL, HORIZONTAL],bind="left",last=0,)
</pre>
<p>The resulting layout for the PDF is like so:
</p><p><a class="image" href="https://pzwiki.wdka.nl/mw-mediadesign/images/thumb/1/1c/E_r_2x2_imposed.png/960px-E_r_2x2_imposed.png"><img alt="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>
</p><p>Documentation for pdfimpose can be found here:
</p><p><a class="external free" href="https://buildmedia.readthedocs.org/media/pdf/pdfimpose/latest/pdfimpose.pdf" rel="nofollow">https://buildmedia.readthedocs.org/media/pdf/pdfimpose/latest/pdfimpose.pdf</a>
</p>
<h2><span class="mw-headline" id="booklet.sh_for_PDF_imposition_into_a_booklet">booklet.sh for PDF imposition into a booklet</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/mw-mediadesign/index.php?title=User:Simon/Trim4/Michaels_booklet_script_for_PDF_imposition&amp;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>I found another way to do imposition using a script Michael wrote called booklet.sh, downloadable here: <a class="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
pdftops -paper match $base.01.pdf $base.01.ps
psbook -s`pdftk_utils.py $base.01.pdf count` $base.01.ps $base.02.ps
psnup -2 -PA4 $base.02.ps $base.03.ps
ps2pdf $base.03.ps $base.booklet.pdf
rm $base.01.pdf $base.01.ps $base.02.ps $base.03.ps
</pre>
<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...
</p>
<!--
NewPP limit report
Cached time: 20200620142122
Cache expiry: 86400
Dynamic content: false
CPU time usage: 0.018 seconds
Real time usage: 0.020 seconds
Preprocessor visited node count: 15/1000000
Preprocessor generated node count: 52/1000000
Postexpand include size: 3629/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/40
Expensive parser function count: 0/100
Unstrip recursion depth: 0/20
Unstrip postexpand size: 419/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00% 4.900 1 -total
70.82% 3.470 1 User:Simon/Trim4/PDF_imposition
26.53% 1.300 1 User:Simon/Trim4/Michaels_booklet_script_for_PDF_imposition
-->
<!-- Saved in parser cache with key wdka_mw_mediadesign-mw_:pcache:idhash:31703-0!canonical and timestamp 20200620142122 and revision id 175212
-->
</div></DOCUMENT_FRAGMENT></div>
</body>
</html>