xtrareports-405260-ai-powered-functionality-desktop-reporting-summarize-translate-in-winforms-document-viewer.md
Follow instructions in this article to integrate AI-powered Summarize and Translate commands into the WinForms Document Viewer.
SummarizeUses generative AI to summarize report content and displays core insights associated with this report.TranslateUses AI services to translate report content to another language.
Tip
You can also integrate the Translate Inline command that allows you to translate reports when previewing a report. Refer to the following help topic for details: Inline Report Translation in the WinForms Document Viewer.
Install the following NuGet packages:
DevExpress.AIIntegration.WinFormsDevExpress.Win.Design (activates design-time features for DevExpress UI controls)The following tutorial uses Azure OpenAI. Refer to the requirements section for information about NuGet packages required for other supported AI services.
The following code snippet registers an Azure OpenAI client at application startup:
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using Microsoft.Extensions.AI;
using System.ClientModel;
internal static class Program {
static string AzureOpenAIEndpoint { get { return "AZURE_OPENAI_ENDPOINT"; } }
static string AzureOpenAIKey { get { return "AZURE_OPENAI_APIKEY"; } }
static string DeploymentName { get { return "MODEL_NAME"; } } // For example, gpt-4.1.
[STAThread]
static void Main(){
IChatClient client = new AzureOpenAIClient(
new Uri(AzureOpenAIEndpoint),
new ApiKeyCredential(AzureOpenAIKey))
.GetChatClient(DeploymentName).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(client);
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
Imports Azure.AI.OpenAI
Imports DevExpress.AIIntegration
Imports Microsoft.Extensions.AI
Imports System.ClientModel
Friend Module Program
Private ReadOnly Property AzureOpenAIEndpoint() As String
Get
Return "AZURE_OPENAI_ENDPOINT"
End Get
End Property
Private ReadOnly Property AzureOpenAIKey() As String
Get
Return "AZURE_OPENAI_APIKEY"
End Get
End Property
Private ReadOnly Property DeploymentName() As String
Get
Return "MODEL_NAME"
End Get
End Property
<STAThread>
Sub Main()
Dim client As IChatClient = (New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New ApiKeyCredential(AzureOpenAIKey))).GetChatClient(DeploymentName).AsIChatClient()
AIExtensionsContainerDesktop.Default.RegisterChatClient(client)
ApplicationConfiguration.Initialize()
Application.Run(New Form1())
End Sub
End Module
Tip
How to Register OpenAI, Azure OpenAI, Ollama, and Semantic Kernel Clients.
Drop the DocumentViewer component from the Toolbox onto a Form.
Create a Ribbon or Standard Toolbar to allow users to invoke the context menu with behavior commands in the Document Viewer.
Specify the Document Source option. Use an object that supplies a document to the Document Viewer.
Follow the steps below to attach a behavior to the Document Viewer control at design time:
Drop the BehaviorManager component from the Toolbox onto a Form.
(For .NET Framework Projects) Use the Register AI-Powered Behaviors option in the BehaviorManager’s smart tag menu to add the “AI-Powered Behaviors” submenu with report behaviors to BehaviorManager.
Use the Edit Behaviors option in the BehaviorManager’s smart tag menu to access the behavior collection.
Add Translate and Summarize behaviors and configure their settings:
The following code activates Summarize and Translate commands in two steps:
Registers behaviors: DocumentSummarizeBehavior and DocumentTranslateBehavior
Attaches behaviors to the Document Viewer control
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;
// ...
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
behaviorManager1.Attach<DocumentSummarizeBehavior>(documentViewer1, behavior => {
behavior.Properties.SummarizationMode = SummarizationMode.Extractive;
});
behaviorManager1.Attach<DocumentTranslateBehavior>(documentViewer1, behavior => {
behavior.Properties.Languages = new LanguageInfo[] {
new LanguageInfo("de-DE"),
new LanguageInfo("es-ES")
};
});
}
}
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.WinForms
' ...
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
behaviorManager1.Attach(Of DocumentSummarizeBehavior)(documentViewer1, Sub(behavior)
behavior.Properties.SummarizationMode = SummarizationMode.Extractive
End Sub)
behaviorManager1.Attach(Of DocumentTranslateBehavior)(documentViewer1, Sub(behavior)
behavior.Properties.Languages = New LanguageInfo() {
New LanguageInfo("de-DE"),
New LanguageInfo("es-ES")
}
End Sub)
End Sub
End Class
Note
Call the BehaviorInitializer.Initialize() method at application startup if your project targets the .NET Framework and you create AI-powered behaviors in code. Otherwise, an exception is thrown.
internal static class Program {
[STAThread]
static void Main() {
//...
// The Initialize() method forcibly initializes the behavior manager in .NET Framework apps.
DevExpress.AIIntegration.WinForms.Reporting.BehaviorInitializer.Initialize();
Application.Run(new Form1());
}
}
You can access the Translate command in the AI context menu of WinForms Document Viewer.
Right-click an opened report or selected report content. Select Translate from the AI Assistant submenu.
A dialog appears. Specify the input text range (selected content, document page, or entire document) and target language. Click “Translate” to generate and display a translation.
Click the copy icon to copy operation output.
You can access the Summarize command in the AI context menu of WinForms Document Viewer.
Right-click an open report or selected report content. Select Summarize from the AI Assistant submenu.
A dialog appears. Specify the input text range for summarization (selected content, document page, or entire document). Click “Summarize” to display the summary.
Click the copy icon to copy operation output.