Its a common problem, at least among students: You have a bunch of Postscript and PDF documents which want to be splitted, merged, converted, set n-up (n downscaled pages placed on one) and maybe manually printed duplex.
In many of these cases, you still cannot avoid the command line (Ok, so maybe if you own Adobe Acrobat, you can, who knows...) and often it still doesn't work as desired. For these reasons I collected a bunch of nice utilities over time which, if used together, provide a rather full-featured toolset for Postscript and PDF document processing. Interestingly, the most helpful of these tools seem to be the ones least known.
BTW: All programs I introduce below are available as stock Debian packages, ready to be installed.
I introduce each program with a paragraph or two and a typical program invokation example only, more details can be found in the corresponding manual pages easily once you know what you're looking for.
The most popular tool for setting Postscript documents n-up probably is psnup from the psutils package. Unfortunately, and less widely known, this tool often produces invalid Postscript as a result which may cause problems on further processing, eg. when printing it on an Epson inkjet printer using some versions of the GutenPrint CUPS printer drivers.
mpage (Debian-package: mpage) provides comparable features and creates much better - and much more compatible - results: mpage -2 eingabe.ps > ausgabe.ps
Just for completeness: impose+ (Debian-package: impose+) also is supposed to perform n-up conversion, even with appropriate up- and downscaling of the converted pages. I could not really get it to work, however.
The standard solution seems to be to convert the PDF to Postscript using pdf2ps (also see below) and to convert the result to n-up using psnup - yuk. ;) The conversion / processing takes ages and produces huge postscript files if it works at all.
pdfnup is much simpler in comparison: pdfnup --nup 2x1 document.pdf # the output is called "document-2x1.pdf"
That's not only much faster than the pdf2ps-psnup-solution, but also much more reliable and it introduces much less information loss: pdf2ps often renders fonts as bitmaps which is avoided by using pdfnup - this results in better looking and smaller PDF files. A rather funny detail: pdfnup uses pdflatex to perform the n-up conversion. ;)
pdfnup belongs to the pdfjam (Debian-Package: pdfjam) toolset, which also contains a script for rotating a PDF document's pages and another tool for concatenating PDFs. (Also see below.)
pdftk (PDF ToolKit) (Debian-Package: pdftk) is the swiss army knife of PDF command line processing. It has too many features to introduce them all, but pdftk can concatenate PDFs, extract single pages or ranges of pages into new documents, it encrypts an decrypts PDFs as well as compress and uncompress them, etc.
An interesting detail: pdftk is written in C++ and uses a Java library for PDF processing which is natively compiled using gcj. :-)
pdfimages, which belongs to xpdf (Debian-Package: xpdf-utils), can extract all or some selected bitmap images from a PDF document as-is. This is much faster than taking screen shots of the displayed PDF document for example and has the additional advantage that the image does not lose any quality: pdfimages -j pdf_with_imgs.pdf imageseries
This example will extract all images from the given PDF document and store them in the current directory using names like imageseries<number>.<ext>
, where <ext> is pbm
for monochrome images, ppm
for other images and, thanks to -j
, jpg
if the embedded image is a JPEG itself.
The usual answer here is pdf2ps
, which belongs to the Ghostscript package and thus uses the Ghostscript engine for the conversion. Ghostscript is getting better in doing this and current Ghostscript releases usually create acceptable results, but pdftops (Watch out for the difference! ;) (Debian-Package: xpdf-utils), which is based on the xpdf engine, produces even better results in virtually all cases. pdftops keeps more elements and fonts as-is, without performing additional rasterization, and thus produces smaller and better looking Postscript documents which can be further post-processed just fine.
pdftops document.pdf # will generate document.ps
Especially by combining the features of the tools I introduced, one gets a powerful toolset for most if not all common Postscript and PDF document processing tasks.
For example, a pdfnup followed by a pdftk cat allows to manually print several related PDF documents duplex, a must have for students at the end of each term. ;)
I hope, you did not already know all programs and maybe learned something use- and helpful.