DocumentBaseBackgroundShape Property
Gets or sets the background shape of the document. Can be null.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public Shape BackgroundShape { get; set; }

Property Value

Type: Shape
Remarks

Microsoft Word allows only a shape that has its ShapeType property equal to Rectangle to be used as a background shape for a document.

Microsoft Word supports only the fill properties of a background shape. All other properties are ignored.

Setting this property to a non-null value will also set the DisplayBackgroundShape to true.

Examples
Shows how to set the background shape of a document.
[C#]

Document doc = new Document();
Assert.IsNull(doc.BackgroundShape);

// A background shape can only be a rectangle
// We will set the colour of this rectangle to light blue
Shape shapeRectangle = new Shape(doc, ShapeType.Rectangle);
doc.BackgroundShape = shapeRectangle;

// This rectangle covers the entire page in the output document
// We can also do this by setting doc.PageColor
shapeRectangle.FillColor = System.Drawing.Color.LightBlue;
doc.Save(ArtifactsDir + "DocumentBase.BackgroundShapeFlatColor.docx");

// Setting the image will override the flat background colour with the image
shapeRectangle.ImageData.SetImage(MyDir + "Images/Watermark.png");
Assert.IsTrue(doc.BackgroundShape.HasImage);

// This image is a photo with a white background
// To make it suitable as a watermark, we will need to do some image processing
// The default values for these variables are 0.5, so here we are lowering the contrast and increasing the brightness
shapeRectangle.ImageData.Contrast = 0.2;
shapeRectangle.ImageData.Brightness = 0.7;

// Microsoft Word does not support images in background shapes, so even though we set the background as an image,
// the output will show a light blue background like before
// However, we can see our watermark in an output pdf
doc.Save(ArtifactsDir + "DocumentBase.BackgroundShapeWatermark.pdf");
See Also