Using 'pdftron.PDF.Stamper' to add & remove Headers, Footers, Watermarks

Q: We are using “pdftron.PDF.Stamper” in PDFNet v5.1 to stamp
headers, footers and watermarks on PDF pages. Stamping of header,
footer and watermarks works.

We need your inputs on deletion of existing Header/Footer/Watermark.

The following line deletes all the stamping of the document (All
Header, Footer and Watermark).
       Stamper.DeleteStamps(_pdfdoc, new PageSet(1,

       Requirement : Using the “pdftron.PDF.Stamper” can, We delete

1. Only Headers of the document
2. Only Footers of the document
3. Only Watermarks of the document

Instead of deleting all stampings of the document.

A: Unfortunately ‘pdftron.PDF.Stamper’ does not differentiate between
Header, Footers, or Watermarks. They are all treated as different
types of stamps.

You could implement the selective deletion using the following

- You would need to tag newly added form xobjects tagged with
'PieceInfo/PDFTRON' in form xoject dictionary with your own tag (e.g.
MyStampType -> Header).

For example:
Obj p = xobj.FindObj("'PieceInfo");
if (p!=null && p.FindObj("PDFTRON")!=null) {
   // -> You have a stamp object, check if the stamp is tagged with
your 'StampType'
   p = xobj.FindObj("MyStampType");
   if (p == null) {
       xobj.PutName("MyStampType", "Header");
       // my_headers.PushBack(xobj);
   // else the stamp is already tagged (e.g. may be a Footer etc.)

All stamps are really form xobjects and are stored under Resources/
XObject on each page. You can access resource dictionary from
page.GetResourceDict(). For example

Obj d = page.GetResourceDict();
if (d!=null) {
  d = d.FindObj("XObject");
  if (d!=null) {
     for (DictIterator itr = d.GetDictIterator(); itr.HasNext();
itr.Hext()) {
        Obj xobj = itr.Value();
         ... use the above code snippet to classify the stamp

You could keep a list (list<Obj>) to each type of stamp (Headers,
Footers, etc.) as shown in the first snippet.

Before the delete operation you could change pdftron private tag in
the stamp dictionary (PieceInfo/PDFTRON/Private -> Watermark) to
something else (e.g. 'WatermarkFalse') on all stamps that should not
be deleted.

After calling Stamper.DeleteStamps(...) you can revert these names
back to 'Watermark' so that they can be further manipulated as stamps.