officefileapi-devexpress-dot-aiintegration-dot-docs-dot-iaidocprocessingservice-dot-summarizeasync-x28-presentation-summarizationmode-cancellationtoken-x29.md
Generates a brief summary of a presentation content.
Namespace : DevExpress.AIIntegration.Docs
Assembly : DevExpress.AIIntegration.Docs.v25.2.dll
NuGet Package : DevExpress.AIIntegration.Docs
Task<string> SummarizeAsync(
Presentation presentation,
SummarizationMode mode = SummarizationMode.Abstractive,
CancellationToken cancellationToken = default(CancellationToken)
)
Function SummarizeAsync(
presentation As Presentation,
mode As SummarizationMode = SummarizationMode.Abstractive,
cancellationToken As CancellationToken = Nothing
) As Task(Of String)
| Name | Type | Description |
|---|---|---|
| presentation | Presentation |
The Presentation instance which content should be summarized.
|
| Name | Type | Default | Description |
|---|---|---|---|
| mode | SummarizationMode | Abstractive |
An enumeration value that indicates summarization mode.
| | cancellationToken | CancellationToken | null |
The token that cancels the task.
|
| Type | Description |
|---|---|
| Task<String> |
The response that contains AI-generated summary.
|
The following code snippet obtains an AI-generated summary and adds it to the first slide:
using DevExpress.AIIntegration.Docs;
using DevExpress.Docs.Presentation;
using System.Drawing;
// See "Register AI extension service" section for implementation code
var docProcessingService = defaultAIExtensionsContainer.CreateAIDocProcessingService();
var presentation = new Presentation(File.ReadAllBytes("Documents/Presentation.pptx"));
string summary = await docProcessingService.SummarizeAsync(
presentation,
SummarizationMode.Extractive,
CancellationToken.None);
Slide slide = new Slide(new SlideLayout(layoutType: SlideLayoutType.Blank, name: "slide"));
AddTextToSlide(slide, summary);
presentation.Slides.Insert(0, slide);
string targetDir = @"C:\Test Documents";
Directory.CreateDirectory(targetDir); // Safe if already exists
string outputPath = Path.Combine(targetDir, "presentation.pptx");
using (FileStream outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
{
presentation.SaveDocument(outputStream, DocumentFormat.Pptx);
}
void AddTextToSlide(Slide slide, string text)
{
Shape shape = new Shape(ShapeType.Rectangle);
shape.X = 0; shape.Y = 0;
shape.Width = presentation.SlideSize.Width;
shape.Height = presentation.SlideSize.Height;
shape.TextArea = new TextArea
{
Text = $"Summary by DevExpress AI Extensions:\r\n{text}",
ParagraphProperties = new ParagraphProperties
{
TextProperties = new TextProperties {
Fill = new SolidFill(Color.FromArgb(168, 177, 184)),
FontSize = 24
}
},
Properties = new TextAreaProperties
{
AutoFit = TextAutoSize.Shape
}
};
shape.Fill = new SolidFill(Color.FromArgb(21, 25, 28));
shape.Outline = new LineStyle { Fill = new SolidFill(Color.FromArgb(21, 25, 28)) };
slide.Shapes.Add(shape);
}
Imports DevExpress.AIIntegration.Docs
Imports DevExpress.Docs.Presentation
Imports System.Drawing
Imports System.IO
Imports System.Threading
Imports System.Threading.Tasks
' See "Register AI extension service" section for implementation code
var docProcessingService = defaultAIExtensionsContainer.CreateAIDocProcessingService()
Async Function Main() As Task
Dim presentation = New Presentation(File.ReadAllBytes("Documents/Presentation.pptx"))
Dim summary As String = Await docProcessingService.SummarizeAsync( _
presentation, _
SummarizationMode.Extractive, _
CancellationToken.None)
Dim slide As New Slide(New SlideLayout(layoutType:=SlideLayoutType.Blank, name:="slide"))
AddTextToSlide(slide, summary, presentation)
presentation.Slides.Insert(0, slide)
Dim targetDir As String = "C:\Test Documents"
Directory.CreateDirectory(targetDir) ' Safe if already exists
Dim outputPath As String = Path.Combine(targetDir, "presentation.pptx")
Using outputStream As New FileStream(outputPath, FileMode.Create, FileAccess.Write)
presentation.SaveDocument(outputStream, DocumentFormat.Pptx)
End Using
End Function
Sub AddTextToSlide(slide As Slide, text As String, presentation As Presentation)
Dim shape As New Shape(ShapeType.Rectangle)
shape.X = 0
shape.Y = 0
shape.Width = presentation.SlideSize.Width
shape.Height = presentation.SlideSize.Height
shape.TextArea = New TextArea With {
.Text = $"Summary by DevExpress AI Extensions:{vbCrLf}{text}",
.ParagraphProperties = New ParagraphProperties With {
.TextProperties = New TextProperties With {
.Fill = New SolidFill(Color.FromArgb(168, 177, 184)),
.FontSize = 24
}
},
.Properties = New TextAreaProperties With {
.AutoFit = TextAutoSize.Shape
}
}
shape.Fill = New SolidFill(Color.FromArgb(21, 25, 28))
shape.Outline = New LineStyle With {
.Fill = New SolidFill(Color.FromArgb(21, 25, 28))
}
slide.Shapes.Add(shape)
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SummarizeAsync(Presentation, SummarizationMode, CancellationToken) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
office-file-api-ai-implementation/CS/Controllers/SummarizeController.cs#L114
case PresentationPart.WholePresentation:
summaryText = await docProcessingService.SummarizeAsync(presentation, summarizationMode);
break;
See Also
IAIDocProcessingService Interface