User:Simon/Trim4/PDF imposition: Difference between revisions
No edit summary |
|||
(22 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== PDF imposition == | |||
Premise: I will write my own script(s) to impose pages from a source PDF:<br> | Premise: I will write my own script(s) to impose pages from a source PDF:<br> | ||
Line 7: | Line 7: | ||
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. | 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. | ||
== | === PDF imposition from scratch === | ||
'''23.09.19'''<br> | |||
I'm working out which commands to use from the command line. The process should be as follows:<br> | |||
#burst the source PDF, keep the name of the source plus page number (-%d) | #burst the source PDF, keep the name of the source plus page number (-%d) | ||
$ pdftk source.pdf burst output source-%d.pdf | $ pdftk source.pdf burst output source-%d.pdf | ||
Results:<br> | |||
[[File:Burst 01.png|frameless]] | |||
[[File:Burst 02.png|frameless]] | |||
To identify the size of a single burst page in pixels, this is the command I used: | |||
$ identify Carrier_burst-1.pdf | |||
which returns this information: | |||
Carrier_burst-1.pdf PDF 398x591 398x591+0+0 16-bit sRGB 19486B 0.000u 0:00.009 | |||
'''26.09.19'''<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... | |||
#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 | |||
After resizing to 50%, the identify command returns these values: | |||
Carrier_burst-1.pdf PDF 199x296 199x296+0+0 16-bit sRGB 51910B 0.000u 0:00.000 | |||
'''27.09.19'''<br> | |||
The next steps are these: | |||
#impose 2up on a page using imagemagick montage command | #impose 2up on a page using imagemagick montage command | ||
#assemble imposed PDFs into a single file | |||
=== Using pdfimpose === | |||
[https://pypi.org/project/pdfimpose/ pdfimpose] 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: | |||
from pdfimpose import impose, VERTICAL, HORIZONTAL | |||
impose(inname=["foo.pdf"],outname="foo-impose.pdf",fold=[VERTICAL, HORIZONTAL],bind="left",last=0,) | |||
The resulting layout for the PDF is like so: | |||
[[File:E r 2x2 imposed.png|300px|frameless]] | |||
Documentation for pdfimpose can be found here: | |||
https://buildmedia.readthedocs.org/media/pdf/pdfimpose/latest/pdfimpose.pdf |
Latest revision as of 21:28, 11 June 2020
PDF imposition
Premise: I will write my own script(s) to impose pages from a source PDF:
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.
PDF imposition from scratch
23.09.19
I'm working out which commands to use from the command line. The process should be as follows:
#burst the source PDF, keep the name of the source plus page number (-%d) $ pdftk source.pdf burst output source-%d.pdf
To identify the size of a single burst page in pixels, this is the command I used:
$ identify Carrier_burst-1.pdf
which returns this information:
Carrier_burst-1.pdf PDF 398x591 398x591+0+0 16-bit sRGB 19486B 0.000u 0:00.009
26.09.19
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...
#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
After resizing to 50%, the identify command returns these values:
Carrier_burst-1.pdf PDF 199x296 199x296+0+0 16-bit sRGB 51910B 0.000u 0:00.000
27.09.19
The next steps are these:
#impose 2up on a page using imagemagick montage command #assemble imposed PDFs into a single file
Using pdfimpose
pdfimpose 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:
from pdfimpose import impose, VERTICAL, HORIZONTAL impose(inname=["foo.pdf"],outname="foo-impose.pdf",fold=[VERTICAL, HORIZONTAL],bind="left",last=0,)
The resulting layout for the PDF is like so:
Documentation for pdfimpose can be found here:
https://buildmedia.readthedocs.org/media/pdf/pdfimpose/latest/pdfimpose.pdf