We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Watermark is Lost after Removing HeaderFooter of Document using Java

I’m trying to remove the header and footer from a word document. But when I do this, the watermark is also removed.

How can I check which header/footer is the watermark?


In your document, the watermark is in the header or footer of document. So, when you remove the header, the watermark is also removed.

The watermark is imported as Shape node into Aspose.Words’ DOM. Please use CompositeNode.GetChildNodes method to get live collection of child nodes of Shape type.


Thanks for your reply. We have updated our example code, but now we got IllegalArgumentException: Cannot insert a node of this type at this location :

for ( HeaderFooter lHeaderFooter : lSection.getHeadersFooters() ) {
      if ( lHeaderFooter != null ) {
        Node lWatermark = null;
        for(Shape shape :(Iterable<? extends Shape>) lHeaderFooter.getChildNodes(NodeType.SHAPE, true)){
          //if(shape.getName().contains("WaterMark")) {
            lWatermark = shape.deepClone( true );
        int lHeaderType = lHeaderFooter.getNodeType();


        if(lWatermark != null){
          HeaderFooter lHFWatermark = new HeaderFooter(aAsposeDoc, lHeaderType);
          lSection.getHeadersFooters().add( lHFWatermark );
          lHFWatermark.appendChild( lWatermark.deepClone( true ) );

We want to delete all headers and footers because we will insert custom headers and footers afterwards.

Is it possible to remove header and footer without removing the watermark, and how can we do that?

Best regards,


Please note that Aspose.Words mimics the behavior of MS Word. The watermark is inserted into the header of document. If you remove header footer from the document, you cannot insert watermark in it. However, you can insert watermark (image) on each page of document by inserting the image on each page under first paragraph of page.

Could you please ZIP and attach your expected output Word document here for our reference? We will then provide you more information about your query.

See below our example:
Memo -Template(1).zip (70.6 KB)


In your expected output Word document, there is no watermark. However, this document contains the header and footers.

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Your problematic output Word file.
  • Please manually create your expected Word document using Microsoft Word.

We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Below the requested resourced:
Original - Output - Expected output.zip (155.9 KB)

Thanks in advance!


In your document, the primary header contains the table and image. Instead of removing all nodes of header, please remove all nodes except the paragraph that contains the image. Please check the attached DOM image of your document.
DOM Image.png (34.4 KB)