title: How to find and remove watermarks in pdf using python?
body: <p>I am currently using python to remove watermarks in PDF files. For example, I have a file like this:
  <a href="https://i.stack.imgur.com/9Edtc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Edtc.png" alt="enter image description here" /></a></p>
  <p>The green shape on the center of the page is the watermark. I think it's not stored in the PDF in text form, because I can't find that text by simply searching using Edge browser (which can read PDF files).
  Also, I cannot find the watermark by image. I extracted all images from the PDF using PyMuPDF, and the watermark (which was supposed to appear on each page) is not to be found.</p>
  <p>The code I used for extracting is like this:</p>
  <pre class="lang-py prettyprint-override"><code>        document = fitz.open(self.input)
          for each_page in document:
              image_list = each_page.getImageList()
              for image_info in image_list:
                  pix = fitz.Pixmap(document, image_info[0])
                  png = pix.tobytes()  # return picture in png format
                  if png == watermark_image:
                      document._deleteObject(image_info[0])
          document.save(out_filename)
  </code></pre>
  <p>So how do I find and remove the watermark using python's libraries? How is the watermark stored inside a PDF?</p>
  <p>Are there any other &quot;magic&quot; libraries that can do this task, other than PyMuPDF?</p>