Skip to content

Instantly share code, notes, and snippets.

@FilBot3
Last active January 12, 2023 14:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FilBot3/57f5e040a7b138ee33023a5671c77d02 to your computer and use it in GitHub Desktop.
Save FilBot3/57f5e040a7b138ee33023a5671c77d02 to your computer and use it in GitHub Desktop.
Printing PDFs as booklets

Printing PDFs as booklets

Overview

Printing a PDF as a booklet helps reduce the page count needed to print, and also make the PDF able to be travel sized. The size of where it becomes unusable is up to you. However, if it's too big to fold and staple, then you shouldn't do this.

Requirements

  • Podman or Docker

Setup

This will require that the file name not include spaces. If the file does have spaces, rename it with underscores or hyphens.

Usage

Converting

Pull/Download the TexLive Docker Image.

podman pull docker.io/texlive/texlive:latest

Now, we'll mount the current working directory into the running container and then convert the file.

Create a script with the following contents.

# podman-texlive.sh
podman run \
  --rm \
  --mount="type=bind,src=$(pwd),dst=/workdir,shared=relabel" \
  --workdir="/workdir" \
  --privileged \
  --userns=keep-id \
  --name="texlive" \
  --hostname="texlive" \
  docker.io/texlive/texlive:latest pdfbook2 \
    --outer-margin=0 \
    --inner-margin=50 \
    --top-margin=0 \
    --bottom-margin=0 \
    $@

This will execute pdfbook2 from the TexLive suite in the container. It will remove any margins that the application adds by default. By default, pdfbook2 will make the odd pages face down or normal, and even pages will be face up or upside down. This makes printing easier with single-side printers without having to rotate the pages.

Including the --short-edge flag will make pdfbook2 make all the pages face the same way. Using this method, you'll need to rotate the stack of papers before printing on the other side.

Now, run the script podman-texlive.sh mydocument.pdf and it will convert that PDF into a booklet PDF.

Printing

  • Open the PDF viewer of choice, this can be Evince, Okular, or LibreOffice Draw.
  • Then, when printing the document, choose to print all pages, but choose the odd pages first.
  • If using --short-edge, simply take the stack of paper and put it back in the paper tray without rotating it.
  • If not using --short-edge, rotate the stack of paper and put it back into the paper tray.
  • In the PDF Viewer, print all even pages.

This should print the booklet and be ready to be folded and stapled.

You may need to modify the margins or fit to page settings of the PDF Viewer's printing preferences as it may add MORE margin that you don't want. I recommend print previewing, or only print 2 to 4 pages so you're not wasting a lot of paper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment