officefileapi-devexpress-dot-aiintegration-dot-docs-dot-iaidocprocessingservice-dot-summarizeasync-x28-pdfdocumentprocessor-summarizationmode-cancellationtoken-x29.md
Generates a brief summary of a document content.
Namespace : DevExpress.AIIntegration.Docs
Assembly : DevExpress.AIIntegration.Docs.v25.2.dll
NuGet Package : DevExpress.AIIntegration.Docs
Task<string> SummarizeAsync(
PdfDocumentProcessor processor,
SummarizationMode mode = SummarizationMode.Abstractive,
CancellationToken cancellationToken = default(CancellationToken)
)
Function SummarizeAsync(
processor As PdfDocumentProcessor,
mode As SummarizationMode = SummarizationMode.Abstractive,
cancellationToken As CancellationToken = Nothing
) As Task(Of String)
| Name | Type | Description |
|---|---|---|
| processor | PdfDocumentProcessor |
The PdfDocumentProcessor 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 retrieves a summary and inserts it into a newly added first page:
using DevExpress.AIIntegration.Docs;
using DevExpress.Drawing;
using DevExpress.Pdf;
using System.Drawing;
// See "Register AI extension service" section for implementation code
var docProcessingService = defaultAIExtensionsContainer.CreateAIDocProcessingService();
using var pdfDocumentProcessor = new PdfDocumentProcessor();
pdfDocumentProcessor.LoadDocument("Documents/FirstLookExported.pdf");
string summary = await docProcessingService.SummarizeAsync(
pdfDocumentProcessor,
SummarizationMode.Extractive,
CancellationToken.None);
PdfPage page = pdfDocumentProcessor.InsertNewPage(1, PdfPaperSize.Letter);
PdfRectangle pageSize = page.CropBox;
AddContentToPage(pdfDocumentProcessor, page, pageSize, summary);
pdfDocumentProcessor.SaveDocument("result.pdf");
// This method draws text on the inserted page
void AddContentToPage(PdfDocumentProcessor pdfDocumentProcessor, PdfPage page,
PdfRectangle pageSize, string text) {
using (PdfGraphics graphics = pdfDocumentProcessor.CreateGraphicsWorldSystem())
{
using (var textBrush = new DXSolidBrush(Color.FromArgb(255, Color.DarkOrange)))
{
DXFont font = new DXFont("Segoe UI", 12, DXFontStyle.Regular);
// Calculate text size
SizeF textSize = graphics.MeasureString(text, font, new PdfStringFormat());
// Calculate an area to draw the text
PointF textPoint = new PointF(0, (float)(pageSize.Height - 10));
RectangleF rectangle = new RectangleF(
0, 10,
(float)pageSize.Width,
(float)(pageSize.Height / 2));
// Draw text at the calculated area
graphics.DrawString(text, font, textBrush, rectangle);
graphics.AddToPageForeground(page);
}
}
}
Imports DevExpress.AIIntegration.Docs
Imports DevExpress.Drawing
Imports DevExpress.Pdf
Imports System.Drawing
Async Function Main() As Task
' See "Register AI extension service" section for implementation code
var docProcessingService = defaultAIExtensionsContainer.CreateAIDocProcessingService()
Using pdfDocumentProcessor As New PdfDocumentProcessor()
pdfDocumentProcessor.LoadDocument("Documents/FirstLookExported.pdf")
Dim summary As String = Await docProcessingService.SummarizeAsync( _
pdfDocumentProcessor, _
SummarizationMode.Extractive, _
CancellationToken.None)
Dim page As PdfPage = pdfDocumentProcessor.InsertNewPage(1, PdfPaperSize.Letter)
Dim pageSize As PdfRectangle = page.CropBox
AddContentToPage(pdfDocumentProcessor, page, pageSize, summary)
pdfDocumentProcessor.SaveDocument("result.pdf")
End Using
End Function
' This method draws text on the inserted page
Private Sub AddContentToPage(pdfDocumentProcessor As PdfDocumentProcessor, page As PdfPage, pageSize As PdfRectangle, text As String)
Using graphics As PdfGraphics = pdfDocumentProcessor.CreateGraphicsWorldSystem()
Using textBrush As New DXSolidBrush(Color.FromArgb(255, Color.DarkOrange))
Dim font As New DXFont("Segoe UI", 12, DXFontStyle.Regular)
' Calculate text size
Dim textSize As SizeF = graphics.MeasureString(text, font, New PdfStringFormat())
' Calculate an area to draw the text
Dim textPoint As New PointF(0, CSng(pageSize.Height - 10))
Dim rectangle As New RectangleF( _
0, 10, _
CSng(pageSize.Width), _
CSng(pageSize.Height / 2))
' Draw text at the calculated area
graphics.DrawString(text, font, textBrush, rectangle)
graphics.AddToPageForeground(page)
End Using
End Using
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SummarizeAsync(PdfDocumentProcessor, 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#L82
case PdfPart.WholeDocument:
summaryText = await docProcessingService.SummarizeAsync(pdfDocumentProcessor, summarizationMode);
break;
See Also
IAIDocProcessingService Interface