10

There is a similar question, but the answers fail to solve the problem of "flattening" annotations, i.e. turning them from annotations into actual content.

One way is to print them to PDF, but that can result in a loss of quality, especially of scanned images in the PDF. Is there a way to achieve this, preferably using a Linux command line tool like pdftk that can preserve everything in the PDF as-is and only adds the annotations as content?

Thomas W.
  • 424
  • 3
  • 15

2 Answers2

3

The accepted answer on the same question, How can I totally flatten a PDF in Mac OS on the command line? seems to work for me to "bake in" or "flatten" PDF annotations as PDF content:

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf input_with_annots.pdf

... and it even seems to preserve the annotation text (so it is copypastable, along with the original text content).

Tested this on Ubuntu 14.04, Ghostscript gs --version 9.10.

sdaau
  • 5,316
  • 8
  • 60
  • 77
  • 1
    This solution preserves image quality for uncompressed images, but JPEGs get re-encoded, which I'd want to avoid. – Thomas W. Nov 29 '17 at 13:14
  • This does not work with stamps. – Bruni Aug 08 '19 at 08:11
  • This does not work on form fields. The data is empty after flatten. – pablorenato Jul 18 '21 at 11:12
  • 1
    With Ubuntu 21.04 it does sadly not preserve "annotations". Well, what I mean by 'that' is the 'annotations' produced by a pen when writing on a PDF. Ah, to be more specific: the annotations remain visible, but they are still stored as 'annotations' (or as whatever), since they disappear when using pdfjam on it later on. – Prof.Chaos Aug 30 '21 at 04:45
  • This similar question/thread [https://superuser.com/questions/370364/how-can-i-totally-flatten-a-pdf-in-mac-os-on-the-command-line/816195#816195] provides an answer that works for my system: pdf2ps -q -sOutputFile=- file.pdf | ps2pdf - file_flat.pdf – Prof.Chaos Aug 30 '21 at 06:19
  • 1
    This doesn’t work anymore. See the update in the linked answer: “EDIT 2020-07-25 This used to work but doesn't anymore. Now these commands continue to preserve the PDF layers.” – Socob Jan 10 '23 at 14:03
3

The best solution I’ve found so far: Open the PDF file in Evince and “Print to File”.

Screenshot of Evince’s Print dialog, with “Print to File” selected

Socob
  • 187
  • 10
  • Can confirm that, unlike Ghostscript, this works like a charm on macOS, however **not** it Preview, but rather in any web browser. – Nikita Karamov May 31 '23 at 23:38