Free Support Forum - aspose.com

Adding a watermark to all pages of a Word Document problem

In the sample project attached I demonstrate adding a watermark image to a MS Word document, however, in 2 out of the 3 test cases the watermark is not being added consistently. Please advise.

Hi

Thanks for your inquiry. I modified your code a little. See the following snippet.

private void AddSpecimenWatermark(Document document)

{

//Create a document builder that will allow us to modify the document.

DocumentBuilder builder = new DocumentBuilder(document);

//Create list of Headers types

System.Collections.ArrayList headerTypeList = new System.Collections.ArrayList();

headerTypeList.Add(HeaderFooterType.HeaderEven);

headerTypeList.Add(HeaderFooterType.HeaderFirst);

headerTypeList.Add(HeaderFooterType.HeaderPrimary);

//The cursor is in the first section already, navigate to the header as this is where

//we want to insert the watermark.

foreach (HeaderFooterType headerType in headerTypeList)

{

builder.MoveToHeaderFooter(headerType);

System.Drawing.Image image = GetSpecimenImage();

//Insert a floating picture.

Shape shape = builder.InsertImage(image);

shape.WrapType = WrapType.None;

shape.BehindText = true;

// Position the image in the center of the page.

shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;

shape.HorizontalAlignment = HorizontalAlignment.Center;

shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;

shape.VerticalAlignment = VerticalAlignment.Center;

}

}

I hope that this will help you.

Best regards

That fixed it. Thanks for the quick reply.