title: Removing watermark stamped from 3rd party application by iText
body: <p>To give you the context, I am trying to remove a watermark from a pdf generated by some 3rd party application. I am trying to write a utility with iText7 which will detect such watermark and remove it.</p>
  <p>Here is the pdf file sample <a href="https://easyupload.io/54zhzs" rel="nofollow noreferrer">https://easyupload.io/54zhzs</a>. The highlighted watermark text I am trying to remove.</p>
  <p><a href="https://i.stack.imgur.com/4nHVQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4nHVQ.png" alt="enter image description here" /></a></p>
  <p>I was first thinking that it could be added as annotation,but I receive <code>annots</code> as null.Had there been annots collection I could have inspected and remove this annotation. This works well when we stamp annotaion with iText itself but here is not that case.</p>
  <pre><code> PdfDocument pdfDoc = new PdfDocument(new PdfReader(filePath), new PdfWriter(destinationfile));
   for (var i = 1; i &lt;= pdfDoc.GetNumberOfPages(); i++)
   {
      PdfDictionary pageDict = pdfDoc.GetPage(i).GetPdfObject();
      PdfArray annots = pageDict.GetAsArray(PdfName.Annots);
      if (annots != null)          
      {
             for (int j = 0; j &lt; annots.Size(); j++)
             {
                   PdfDictionary annotation = annots.GetAsDictionary(j); 
                   if (PdfName.Watermark.Equals(annotation.GetAsName(PdfName.Subtype)))
                   {
                       annotation.Clear();
                   }                        
             }
       }
    }
   pdfDoc.Close();
  </code></pre>
  <p>Next, in the second approach I tried to acquire the <code>PdfObject</code> like this, but I am clueless here how to identify the correct object which I want to delete.</p>
  <pre><code>PdfDictionary pageDict = pdfDoc.GetFirstPage().GetPdfObject();
  PdfArray fields = pageDict.GetAsArray(PdfName.Fields);
  PdfDictionary resources = pageDict.GetAsDictionary(PdfName.Resources);
  PdfArray xObjects = resources.GetAsArray(PdfName.ProcSet);
  foreach (PdfObject obj in xObjects)
  {
     // not sure what to do from here
  }
  </code></pre>
  <p>This is the debug result what I get. I think in the last ProcSet this watermark is an image layer, but I am not sure what to identify that.</p>
  <p><a href="https://i.stack.imgur.com/lQiZZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lQiZZ.png" alt="enter image description here" /></a>
  Am I on right track or is there any other solutions?</p>