public void BackgroundShape() { //ExStart //ExFor:DocumentBase.BackgroundShape //ExSummary:Shows how to set a background shape for every page of a document. Document doc = new Document(); Assert.IsNull(doc.BackgroundShape); // The only shape type that we can use as a background is a rectangle. Shape shapeRectangle = new Shape(doc, ShapeType.Rectangle); // There are two ways of using this shape as a page background. // 1 - A flat color: shapeRectangle.FillColor = System.Drawing.Color.LightBlue; doc.BackgroundShape = shapeRectangle; doc.Save(ArtifactsDir + "DocumentBase.BackgroundShape.FlatColor.docx"); // 2 - An image: shapeRectangle = new Shape(doc, ShapeType.Rectangle); shapeRectangle.ImageData.SetImage(ImageDir + "Transparent background logo.png"); // Adjust the image's appearance to make it more suitable as a watermark. shapeRectangle.ImageData.Contrast = 0.2; shapeRectangle.ImageData.Brightness = 0.7; doc.BackgroundShape = shapeRectangle; Assert.IsTrue(doc.BackgroundShape.HasImage); // 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(ArtifactsDir + "DocumentBase.BackgroundShape.Image.pdf"); //ExEnd doc = new Document(ArtifactsDir + "DocumentBase.BackgroundShape.FlatColor.docx"); Assert.AreEqual(System.Drawing.Color.LightBlue.ToArgb(), doc.BackgroundShape.FillColor.ToArgb()); Assert.Throws <ArgumentException>(() => { doc.BackgroundShape = new Shape(doc, ShapeType.Triangle); }); #if NET48 || NET5_0 || JAVA Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ArtifactsDir + "DocumentBase.BackgroundShape.Image.pdf"); XImage pdfDocImage = pdfDocument.Pages[1].Resources.Images[1]; Assert.AreEqual(400, pdfDocImage.Width); Assert.AreEqual(400, pdfDocImage.Height); Assert.AreEqual(ColorType.Rgb, pdfDocImage.GetColorType()); #endif }