Presentation.GetActualShapeBounds(Slide, FilledShape) Method
Returns the size of the shape on the specified slide.
Namespace: DevExpress.Docs.Presentation
Assembly: DevExpress.Docs.Presentation.v25.1.dll
NuGet Package: DevExpress.Docs.Presentation
Declaration
Parameters
Name | Type | Description |
---|---|---|
slide | Slide | The slide. |
shape | FilledShape | The shape that belongs to the slide. |
Returns
Type | Description |
---|---|
RectangleF | The shape boundaries. |
Remarks
The following code snippet replaces a placeholder shape with an image:
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;
namespace PresentationApiSample;
public class Program {
public static void Main(string[] _) {
// Load an existing presentation from a file
Presentation presentation = new Presentation(File.ReadAllBytes(@"..\..\..\data\my-presentation.pptx"));
// Load an image
string imagePath = @"..\..\..\data\table.png";
Stream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
var image = DXImage.FromStream(stream);
// Create a new slide based on Object layout
Slide slide = new Slide(SlideLayoutType.Object);
// Find the Body placeholder shape on the slide
var bodyPlaceholderShape = slide.Shapes.Find<Shape>(x => x.PlaceholderSettings.Type == PlaceholderType.Body);
if (bodyPlaceholderShape != null) {
// Get the actual bounds of the Body placeholder
RectangleF rect = presentation.GetActualShapeBounds(slide, bodyPlaceholderShape);
// Remove the Body placeholder shape
slide.Shapes.Remove(bodyPlaceholderShape);
// Add the image as a picture shape in the same position and size
PictureShape picture = new PictureShape(image, rect.X, rect.Y, rect.Width, rect.Height);
slide.Shapes.Add(picture);
}
// Add the new slide to the presentation
presentation.Slides.Add(slide);
// Save the modified presentation to a new PPTX file
FileStream outputStream = new FileStream(@"D:\\saved-document.pptx", FileMode.Create);
presentation.SaveDocument(outputStream);
outputStream.Dispose();
}
}
See Also