

In this example, removing lines 129 through 132 would remove 2 yellow rectangles. In order to remove such things you would have write a script that analyzes the contents source, locates those commands and removes them.

The re commands in lines 129 & 131 draw rectangles, lines 130 & 132, fill them, line 128 defines color yellow, etc. You will then see this in object with xref = 5: What happens, can be seen when you decompress a page's /Contents object (either via PyMuPDF or via the MuPDF command line tool: mutool clean -d test.pdf test-expand.pdf). They indeed are no annotations, Whoever created the PDF, has decided to draw those rectangles permanently - very much as you would when using Page.drawRect in PyMuPDF.
