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: 20.3
public Shape BackgroundShape { get; set; }

Property Value

Type: Shape

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.

Shows how to set the background shape of a document.
Document doc = new Document();

// A background shape can only be a rectangle
// We will set the color 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 color with the image
shapeRectangle.ImageData.SetImage(ImageDir + "Transparent background logo.png");

// 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.BackgroundShape.pdf");
See Also