15 KiB
The Ghostscript Imposition¶
Imposition is one of the fundamental steps in the prepress printing process. It consists of the arrangement of the printed product’s pages on the printer’s sheet, in order to obtain faster printing, simplify binding and reduce paper waste.
Correct imposition minimizes printing time by maximizing the number of pages per impression, reducing cost of press time and materials. To achieve this, the printed sheet must be filled as fully as possible.
Paged media: A timeline¶
1980s
1990s
Dave Raggett's Touch of Style tutorial from/updated 2002, is a good introduction to and reflection on using CSS for the web -- notice there's almost no discussion of print -- it's all about how pages get rendered online, aka in a web browser. This is still the focus of CSS today... but...
TODAY
https://en.wikipedia.org/wiki/CSS
CSS3 includes an extensive Paged Media Specification describing how CSS can be also used to render "paged media" (ie when printed or saved as PDF). Most browsers do not implement these rules (except in some cases when you print a page). The Weasyprint python library implements some of these guidelines.
The "UNIX" philosophy of small tools composed together (and the pipeline)¶
Use the !shell¶
Jupyter (and ipython before it) supports the use of shell commands fluidly along side your python code. When the line starts with a ! (the exclamation point, often called bang by command line users), the command is interpreted as a shell command and performed, the results displayed below, just like with python code. Note that the shell has different rules about what a good structure is. In any case the first word is the name of a command...
!date
!whoami
!ls
An zine introduction to the terminal¶
MAN oh MAN¶
A very important concept from the UNIX / Linux / Libre software world is that documentation ought to be seen as an full part of the distribution of software. When software is installed, it often installs a so-called "man page" (for manual). You can then read the manual with the "man" command followed by the command you are interested in...
!man gs
If you read the manual on the man command itself (type man man)... You see it supports different output formats. The -t option outputs in the Postscript language.
!man -t gs
Not very pretty, luckily we have ghostscript which is the basis of many smaller commands, such as one to convert postscript to pdf. The command is called ps2pdf. When can connect the two commands together in so called pipeline with the | character -- which is called the pipe because of this usage.
First let's make a folder for our manuals
!mkdir -p man
Now let's run man gs and pipe the output to ps2pdf, saving in the file man/gs.pdf.
!man -t gs | ps2pdf - man/gs.pdf
Some links that were used in developing some of this notebook:
Make some man-uals with ps2pdf¶
!man -t psnup | ps2pdf - man/psnup.pdf !man -t pstops | ps2pdf - man/pstops.pdf !man -t ps2pdf | ps2pdf - man/ps2pdf.pdf !man -t pdf2ps | ps2pdf - man/pdf2ps.pdf !man -t pdftk | ps2pdf - man/pdftk.pdf !man -t pdfposter | ps2pdf - man/pdfposter.pdf !man -t poster | ps2pdf - man/poster.pdf
# NB These tools are often part of other packages of tools, for instanced: # apt install ghostscript psutils pdfposter
Read the label with pdfinfo¶
PDFs have useful info like number of pages and the (default) page size, but also can contain various metadata like Title, Keywords, and Author, and the "Producer" which often indicates what software was used to make the file.
!pdfinfo txt/language.pdf
Back to the Future with pdf2ps¶
Many of the commands discussed here have their origins in the 1990s and were written to work with Postscript. Luckily there's also a pdf2ps command to go from PDF to Postscript. This command outputs (unless otherwise told) in a file with the same name but extension .ps
!pdf2ps txt/language.pdf
psnup saves trees¶
!psnup -2 language.ps psnup.ps
To look at it, run the ps2pdf...
!ps2pdf psnup.ps psnup.pdf
AND LOOK HERE: psnup.pdf
!psnup -2 -p a3 -s a3 language.ps psnup.ps
Repeat the steps above to see it (make sure you close the PDF to reload it).
The -c option lays out in column order (instead of rows). Check out the manual.
!psnup -16 -c language.ps psnup.ps
!psnup -16 -c -p a0 language.ps psnup.ps
pdftk is another PDF toolkit¶
This command can do many things. Let's use it to extract a page
!pdftk A=txt/language.pdf cat A1 output 1.pdf
Scale (among other things) with the multi-faceted pstops¶
!pdf2ps 1.pdf 1.ps # Scale up A4 to A2, A0 !pstops "0@2.0" -pa2 1.ps 1.output.ps !pstops "0@4.0" -pa0 1.ps 1.a0.ps
NB: When subsequently using ps2pdf on a resized postscript file, you should explictly specify the output paper size:
!ps2pdf -sPAPERSIZE=a0 1.a0.ps 1.a0.pdf
!pdfinfo 1.a0.pdf
From pdf to ps and back again with a pipeline sandwich¶
You might say, what a drag that pstops only scales postscript files and not PDF, well just wrap it in a Pipeline sandwich...
!pdf2ps 1.pdf - | pstops "0@4.0" -pa2 | ps2pdf -sPAPERSIZE=a0 - 1.a0.pdf
Make a blank PDF with python and reportlab.pdfgen.canvas¶
from reportlab.pdfgen.canvas import Canvas from reportlab.lib.pagesizes import A4 c = Canvas("blanka4.pdf", pagesize=A4, bottomup=0) c.showPage() c.save()
Tile and zoom with poster¶
From the poster manual:
Poster can be used to create a large poster by building it from multiple pages and/or printing it on large me-dia. Itexpects as input a generic (encapsulated) postscript file, normally printing on a single page.Theoutput is again a postscript file, maybe containing multiple pages together building the poster.The outputpages bear cutmarks and have slightly overlapping images for easier assembling. The input picture will bescaled to obtain the desired size
#!poster -mA3 -pA0 1.ps | ps2pdf - > poster.poster.pdf !poster -v -c0 -iA4 -mA4 -pA0 1.ps | ps2pdf - > poster.poster.pdf
The newer pdfposter works directly with PDF files, and has slightly different options.
For example to prints an A4 input file on 8 A3 pages, forming an A0 poster:
!pdfposter -mA3 -pA0 1.pdf pdfposter.pdf