UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

Document Understanding 活动

上次更新日期 2026年4月22日

OCR 原生活动类

定义

  • 命名空间: UiPath.OCR.Contracts.Activities
  • 程序集: UiPath.OCR.Contracts

描述

必须实现的抽象类,才能从 Workflow Foundation 框架构造 NativeActivity

成员

方法
  • BeforeExecute(System.Activities.NativeActivityContext) System.Collections.Generic.Dictionary<string, object> - 覆盖此方法以计算并提供除图像参数以外的所有活动输入参数,并以字典形式返回活动输入参数,其中键为参数名称,值为参数值。
    备注:

    At design time, when no context is available, the method's parameters are null. In this case, the activity arguments can't be read, so you may want to provide default values for them.

  • Execute(System.Activities.NativeActivityContext) void Execute(System.Activities.NativeActivityContext - 您可以覆盖此方法以实施活动代码。 由工作流运行时调用,以执行活动。 它还提供对跟踪、变量和参数的访问权限。
  • OCRNativeActivity.OCRNativeActivity() - 活动构造函数。
  • OnSuccess(System.Activities.NativeActivityContext, UiPath.OCR.Contracts.DataContracts.OCRResult) void OnSuccess(System.Activities.NativeActivityContext context, UiPath.OCR.Contracts.DataContracts.OCRResult result) - 计算 OCR 结果后调用此方法。 它可用于设置输出参数或任何其他最终操作。
  • PerformOCRAsync(System.Drawing.Image, System.Collections.Generic.Dictionary<string, object>, System.Threading.CancellationToken) - Processes an image and returns the extracted text information. The Options parameter is a dictionary of activity arguments having as key the argument name and as value the argument value.
属性
  • ExtractWords - 获取或设置是否应提取单词。
  • Image System.Activities.InArgument<System.Drawing.Image> - 要处理的图像。
  • Language System.Activities.InArgument<string> - OCR 引擎从用户界面元素中提取字符串所使用的语言。
  • Output System.Activities.OutArgument<UiPath.OCR.Contracts.OcrActivityResult> - 活动输出。 Legacy,过时的参数。
  • Text System.Activities.OutArgument<string> - 提取的字符串。

代码示例

[DisplayName("Sample OCRNativeActivity")]
internal class SampleOCRNativeActivity : OCRNativeActivity
    {
        public InArgument<string> CustomInput { get; set; }

        public OutArgument<string> CustomOutput { get; set; }

        public override Task<OCRResult> PerformOCRAsync(Image image, Dictionary<string, object> options, CancellationToken ct)
        {
            string customInput = options[nameof(CustomInput)] as string;
            string text = $"Text from {nameof(SampleOCRNativeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

        protected override void OnSuccess(NativeActivityContext context, OCRResult result)
        {
            CustomOutput.Set(context, $"Custom output: '{result.Text}' has {result.Words.Length} words.");
        }

        protected override Dictionary<string, object> BeforeExecute(NativeActivityContext context)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }
[DisplayName("Sample OCRNativeActivity")]
internal class SampleOCRNativeActivity : OCRNativeActivity
    {
        public InArgument<string> CustomInput { get; set; }

        public OutArgument<string> CustomOutput { get; set; }

        public override Task<OCRResult> PerformOCRAsync(Image image, Dictionary<string, object> options, CancellationToken ct)
        {
            string customInput = options[nameof(CustomInput)] as string;
            string text = $"Text from {nameof(SampleOCRNativeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

        protected override void OnSuccess(NativeActivityContext context, OCRResult result)
        {
            CustomOutput.Set(context, $"Custom output: '{result.Text}' has {result.Words.Length} words.");
        }

        protected override Dictionary<string, object> BeforeExecute(NativeActivityContext context)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }
  • 定义
  • 描述
  • 成员
  • 代码示例

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新