User:Simon/Trim4/PDF imposition: Difference between revisions
No edit summary |
|||
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. | ||
== | == 23.09.19 == | ||
First, I'm working out which commands to use from the command line. The process should be as follows:<br> | First, 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> | |||
#resize the resulting burst single page PDF (this only does one - needs Python to iterate) | #resize the resulting burst single page PDF (this only does one - needs Python to iterate) | ||
Line 17: | Line 20: | ||
#or to resize to specific pixel dimensions such as 256x256 | #or to resize to specific pixel dimensions such as 256x256 | ||
$ magick mogrify -resize 256x256 new_source.pdf | $ magick mogrify -resize 256x256 new_source.pdf | ||
Results: | |||
#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 | #assemble imposed PDFs into a single file | ||
== 24.09.19 == | |||
Sidenote: I found another way to do imposition using a script Michael wrote called booklet.sh, downloadable here: https://git.xpub.nl/murtaugh/95layouts<br> | |||
It's a shell script that can run in the bin folder from my home directory. It needs a few dependencies to run (mainly psutils). | |||
# Requirements: psutils, pdftk, python3 with reportlab (make_blank_pdf.py) | |||
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 | |||
NB: 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... |
Revision as of 16:51, 25 September 2019
Hackpact 1: 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.
23.09.19
First, 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
Results:
#resize the resulting burst single page PDF (this only does one - needs Python to iterate) $ magick mogrify -resize 50% new_source.pdf #or to resize to specific pixel dimensions such as 256x256 $ magick mogrify -resize 256x256 new_source.pdf
Results:
#impose 2up on a page using imagemagick montage command
#assemble imposed PDFs into a single file
24.09.19
Sidenote: I found another way to do imposition using a script Michael wrote called booklet.sh, downloadable here: https://git.xpub.nl/murtaugh/95layouts
It's a shell script that can run in the bin folder from my home directory. It needs a few dependencies to run (mainly psutils).
# Requirements: psutils, pdftk, python3 with reportlab (make_blank_pdf.py) 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
NB: 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...