Skip to main content
All docs
V24.2

Summarize and Translate Reports in the WinForms Document Viewer

  • 4 minutes to read

Follow instructions in this article to integrate AI-powered Summarize and Translate commands into the WinForms Document Viewer.

Summarize
Uses generative AI to summarize report content and displays core insights associated with this report.
Translate
Uses AI services to translate report content to another language.

Activate AI Assistant

Install NuGet Packages

Install the following NuGet packages:

The following tutorial uses Azure OpenAI. Refer to the requirements section for information about NuGet packages required for other supported AI services.

Register AI Client

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 "gpt-4o-mini"; } }
    [STAThread]
    static void Main(){
        IChatClient client = new AzureOpenAIClient(
            new Uri(AzureOpenAIEndpoint),
            new ApiKeyCredential(AzureOpenAIKey))
                .AsChatClient(DeploymentName);
        AIExtensionsContainerDesktop.Default.RegisterChatClient(client);
        ApplicationConfiguration.Initialize();
        Application.Run(new Form1());
    }
}

Note

Review the following help topic for information on how to register other supported AI services: How to Register an AI Client.

Add Document Viewer

  1. Drop the DocumentViewer component from the Toolbox onto a Form.
  2. Create a Ribbon or Standard Toolbar to allow users to invoke the context menu with behavior commands in the Document Viewer.

    Create a Toolbar

  3. Specify the Document Source option. Use an object that supplies a document to the Document Viewer.

Create and Configure AI Assistant Behaviors

Follow the steps below to attach a behavior to the Document Viewer control at design time:

  1. Drop the BehaviorManager component from the Toolbox onto a Form.
  2. Use the Edit Behaviors option in the BehaviorManager’s smart tag menu to access the behavior collection.
  3. Add Translate and Summarize behaviors and configure their settings:

    Add behaviors

    The following settings are available:

    • Summarization Mode (for Summarize behavior)

      Abstractive mode understands the text and rephrases it in a concise form. Extractive mode extracts key sentences or phrases from the original text.

    • Language (for Translate behavior)

      Specifies target languages/cultures for text translation.

    • Temperature

      Controls the randomness of the output. Lower temperatures (value: 0-1) yield more predictable and focused outputs, while higher temperatures (value: 1-2) produce more diverse and creative responses.

    • Target

      Attaches behaviors to DevExpress controls.

Create and Configure AI Assistant Behaviors at Runtime

The following code activates Summarize and Translate commands in two steps:

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")
                };
            });
    }
}

Use Translate Command

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.

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.

Translate dialog

Click the copy icon to copy operation output.

Use Summarize Command

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.

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.

Summarize dialog

Click the copy icon to copy operation output.