Welcome, guest | Sign In | My Account | Store | Cart
import fitz
doc = fitz.open("some.pdf")      # open pdf
page = doc[n]                    # open the page (0-based number)
rtab = []                        # store all rectangles here
annot = page.firstAnnot          # read first annotation
while annot:
	rtab.append(annot.rect)  # store rectangle
	annot = annot.next       # read next annot

i = len(rtab)-1                  # point to last rectangle

annot = page.firstAnnot          # cycle thru annots again
while annot:
	annot.setRect(rtab[i])   # give it a new place
	i -= 1                   # count backwards
	annot = annot.next       
	
doc.save("some-reversed.pdf")    # save PDF with reversed annotations

History