PageSetupPageWidth Property |
Namespace: Aspose.Words
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // The best place for the watermark image is in the header or footer so it is shown on every page builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); Image image = Image.FromFile(ImageDir + "Transparent background logo.png"); // Insert a floating picture Shape shape = builder.InsertImage(image); shape.WrapType = WrapType.None; shape.BehindText = true; shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; shape.RelativeVerticalPosition = RelativeVerticalPosition.Page; // Calculate image left and top position so it appears in the center of the page shape.Left = (builder.PageSetup.PageWidth - shape.Width) / 2; shape.Top = (builder.PageSetup.PageHeight - shape.Height) / 2; doc.Save(ArtifactsDir + "DocumentBuilder.InsertWatermark.doc");
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // The best place for the watermark image is in the header or footer so it is shown on every page builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); using (SKBitmap image = SKBitmap.Decode(ImageDir + "Transparent background logo.png")) { // Insert a floating picture Shape shape = builder.InsertImage(image); shape.WrapType = WrapType.None; shape.BehindText = true; shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; shape.RelativeVerticalPosition = RelativeVerticalPosition.Page; // Calculate image left and top position so it appears in the center of the page shape.Left = (builder.PageSetup.PageWidth - shape.Width) / 2; shape.Top = (builder.PageSetup.PageHeight - shape.Height) / 2; } doc.Save(ArtifactsDir + "DocumentBuilder.InsertWatermarkNetStandard2.doc");
// This creates a builder and also an empty document inside the builder DocumentBuilder builder = new DocumentBuilder(); // By default, the image is inline Shape shape = builder.InsertImage(ImageDir + "Logo.jpg"); // Make the image float, put it behind text and center on the page shape.WrapType = WrapType.None; // Make position relative to the page shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; shape.RelativeVerticalPosition = RelativeVerticalPosition.Page; // Set the shape's coordinates, from the top left corner of the page shape.Left = 100; shape.Top = 80; // Set the shape's height shape.Height = 125.0; // The width will be scaled to the height and the dimensions of the real image Assert.AreEqual(125.0, shape.Width); // The Bottom and Right members contain the locations of the bottom and right edges of the image Assert.AreEqual(shape.Top + shape.Height, shape.Bottom); Assert.AreEqual(shape.Left + shape.Width, shape.Right); builder.Document.Save(ArtifactsDir + "Image.CreateFloatingPositionSize.docx");