background_shape property

DocumentBase.background_shape property

Gets or sets the background shape of the document. Can be None.

@property
def background_shape(self) -> aspose.words.drawing.Shape:
    ...

@background_shape.setter
def background_shape(self, value: aspose.words.drawing.Shape):
    ...

Remarks

Microsoft Word allows only a shape that has its ShapeBase.shape_type property equal to ShapeType.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 ViewOptions.display_background_shape to True.

Examples

Shows how to set a background shape for every page of a document.

doc = aw.Document()
self.assertIsNone(doc.background_shape)
# The only shape type that we can use as a background is a rectangle.
shape_rectangle = aw.drawing.Shape(doc, aw.drawing.ShapeType.RECTANGLE)
# There are two ways of using this shape as a page background.
# 1 -  A flat color:
shape_rectangle.fill_color = aspose.pydrawing.Color.light_blue
doc.background_shape = shape_rectangle
doc.save(ARTIFACTS_DIR + 'DocumentBase.background_shape.flat_color.docx')
# 2 -  An image:
shape_rectangle = aw.drawing.Shape(doc, aw.drawing.ShapeType.RECTANGLE)
shape_rectangle.image_data.set_image(IMAGE_DIR + 'Transparent background logo.png')
# Adjust the image's appearance to make it more suitable as a watermark.
shape_rectangle.image_data.contrast = 0.2
shape_rectangle.image_data.brightness = 0.7
doc.background_shape = shape_rectangle
self.assertTrue(doc.background_shape.has_image)
save_options = aw.saving.PdfSaveOptions()
save_options.cache_background_graphics = False
# Microsoft Word does not support shapes with images as backgrounds,
# but we can still see these backgrounds in other save formats such as .pdf.
doc.save(ARTIFACTS_DIR + 'DocumentBase.background_shape.image.pdf', save_options)

See Also