Batch printing of multiple Office documents

There are times when one faces the challenge of printing a lot of office documents in duplex mode. Instead of opening each document and print it manually an IT guy wants to find a solution that is as painless as possible.

For this purpose ref. [1] illustrates the principal idea quite nicely. On the command line one can rather quickly convert an arbitrary number of Libre Office documents into PDFs by

find . -name "*.odt" -exec soffice \
--headless --convert-to pdf \
--outdir /tmp/ "{}" \;

This command finds all ODT files under the current directory tree and converts it into a PDF file, which is stored in /tmp. Caveat, multiple ODT files with identical names will result in only one PDF file ;)

So far we have not gained much — except that we might have lost some files due to duplicate file names. Now we want to concatenate the PDFs using e.g. PDFtk [2]

pdftk "/tmp/*.pdf" cat output my_merged_documents.pdf

Now we are at the luxury point of having only one file that has to be printed. This could be done using the 'lp' command [3], if one knows the arguments for duplex printing, or comfortably with any PDF viewer.

Et voila!

References

  1. http://www.firewing1.com/blog/2012/04/28/printing-odt-documents-command-line-and-mass-pdf-exporting
  2. https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
  3. http://linux.die.net/man/1/lp