I have a PDF document (slides) with annotations performed with a pen. For the handout, I want to print them in 4-on-1 fashion, and thus of course including the annotations.

There are some solutions on StackOverflow explaining how this 4-on-1 printout can be achieved, but by default these solutions do not preserve the annotations. The problem here seems to be that annotations are on a different layer of the PDF, which is ignored in these standard conversions that put multiple pages into one.

Thus the question is how this 'multiple pages onto one' printing can be done without ignoring/throwing away the annotations.

  • 3
    This is a perfectly valid question for Ubuntu, because, it is not like "How to do this using javascript?", rather it is "how to do this with tools available in Ubuntu". Aug 30 at 6:51

Description works for:

Ubuntu          21.04
pdfjam          3.03
GPL Ghostscript 9.53.3 (2020-10-01)

I created this question after having found the solution -- to make it easier for others (since some commands I found were outdated etc.)

Key to finding the solution is knowing that 'preserving' the annotations is called 'flattening', which essentially puts the annotation layer into the 'standard' one(s).

Thus, we have three steps:

  1. flattening: pdf2ps -q -sOutputFile=- input.pdf | ps2pdf - out-flat.pdf
  2. merging 4on1: pdfjam --nup 2x2 out-flat.pdf --outfile out-4on1.pdf --landscape

For me, step 1 produced a PDF that was significantly larger than the original, so an alternative third step might a compression:

  1. compressing: gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -q -o out-4on1-compressed.pdf out-4on1.pdf

Note that for compression there are multiple compression rates that you could choose, the one chosen here (ebook) is the one best for my purposes. More details below.

Since I will have to do this on a regular basis, I created a convenient script for that. Hope it's helpful to others as well!


# argument 1: input filename
# argument 2: compression rate (optional)

# remove file ending to be able chaning the filename
filename=$(basename -- "$1")

# compile the annotations inte the main layer(s)
pdf2ps -q -sOutputFile=- $1 | ps2pdf - $prefix-flattened.pdf

# put 4 slides into one per page, landscape mode
pdfjam --nup 2x2 $prefix-flattened.pdf --outfile $prefix-4on1-largeFile.pdf --landscape

# compress
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/${2:-ebook} -q -o $prefix-4on1.pdf $prefix-4on1-largeFile.pdf

# delete intermediate files
rm ./$prefix-flattened.pdf
rm ./$prefix-4on1-largeFile.pdf

Don't forget to make the script file executable (e.g. via chmod +x 4on1-script.sh). The script deletes all the intermediate files. Also it creates a useful filename, for which 'identifying' a file's prefix was required. Its first argument is the input filename. Its second argument is optional and determines compression quality. Default value is ebook, other values are:

  • screen: selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • ebook: selects medium-resolution output similar to the Acrobat Distiller "eBook" setting. (chosen here)
  • printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
  • default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.

If you like this solution consider also liking the ones I based this one upon:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.