officefileapi-devexpress-dot-docs-dot-presentation-dot-presentation-dot-getactualshapebounds-x28-devexpress-dot-docs-dot-presentation-dot-slide-devexpress-dot-docs-dot-presentation-dot-filledshape-x29.md
Returns the size of the shape on the specified slide.
Namespace : DevExpress.Docs.Presentation
Assembly : DevExpress.Docs.Presentation.v25.2.dll
NuGet Package : DevExpress.Docs.Presentation
public RectangleF GetActualShapeBounds(
Slide slide,
FilledShape shape
)
Public Function GetActualShapeBounds(
slide As Slide,
shape As FilledShape
) As RectangleF
| Name | Type | Description |
|---|---|---|
| slide | Slide |
The slide.
| | shape | FilledShape |
The shape that belongs to the slide.
|
| Type | Description |
|---|---|
| RectangleF |
The shape boundaries.
|
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();
}
}
Imports DevExpress.Docs.Presentation
Imports DevExpress.Drawing
Namespace PresentationApiSample
' Main entry point for the application
Public Class Program
Public Shared Sub Main(__ As String())
' Load an existing presentation from a file
Dim presentation As Presentation = New Presentation(File.ReadAllBytes("..\..\..\data\my-presentation.pptx"))
' Load an image
Dim imagePath = "..\..\..\data\table.png"
Dim stream As Stream = New FileStream(imagePath, FileMode.Open, FileAccess.Read)
Dim image = DXImage.FromStream(stream)
' Create a new slide based on Object layout
Dim slide As Slide = New Slide(SlideLayoutType.Object)
' Find the Body placeholder shape on the slide
Dim bodyPlaceholderShape = slide.Shapes.Find(Of Shape)(Function(x) x.PlaceholderSettings.Type = PlaceholderType.Body)
If bodyPlaceholderShape IsNot Nothing Then
' Get the actual bounds of the Body placeholder
Dim 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
Dim picture As PictureShape = New PictureShape(image, rect.X, rect.Y, rect.Width, rect.Height)
slide.Shapes.Add(picture)
End If
' Add the new slide to the presentation
presentation.Slides.Add(slide)
' Save the modified presentation to a new PPTX file
Dim outputStream As FileStream = New FileStream("D:\\saved-document.pptx", FileMode.Create)
presentation.SaveDocument(outputStream)
outputStream.Dispose()
End Sub
End Class
End Namespace
See Also