activities
latest
false
UiPath logo, featuring letters U and I in white
Document Understanding Activities
Last updated Nov 26, 2024

OCRCodeActivity Class

Definition

  • Namespace: UiPath.OCR.Contracts.Activities
  • Assembly: UiPath.OCR.Contracts

Description

An abstract class that must be implemented in order to construct a CodeActivity from the Workflow Foundation framework.

Members

Methods
  • BeforeExecute(System.Activities.CodeActivityContext) System.Collections.Generic.Dictionary<string, object> - Overrides this method to compute and provide all the activity input arguments, other than the Image argument, and returns the activity input arguments as a dictionary where the key is the argument name and the value is the argument value.
    Note: 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.CodeActivityContext) System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Drawing.Rectangle, string>>
  • OCRCodeActivity()
  • OnSuccess(System.Activities.CodeActivityContext, UiPath.OCR.Contracts.DataContracts.OCRResult) void OnSuccess(System.Activities.CodeActivityContext context, UiPath.OCR.Contracts.DataContracts.OCRResult result) - This method is called after computing the OCR result. It can be used to set output arguments or any other final operations.
  • PerformOCRAsync(System.Drawing.Image, System.Collections.Generic.Dictionary<string, object>, System.Threading.CancellationToken) System.Threading.Tasks.Task<UiPath.OCR.Contracts.DataContracts.OCRResult> - 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.
Properties
  • ExtractWords - Gets or sets if the words should be extracted.
  • Image System.Activities.InArgument<System.Drawing.Image> - Image to be processed.
  • Language System.Activities.InArgument<string> -
  • Output System.Activities.OutArgument<UiPath.OCR.Contracts.OcrActivityResult> -
  • Text System.Activities.OutArgument<UiPath.OCR.Contracts.OcrActivityResult> -

Code Sample

[DisplayName("Sample OCRCodeActivity")]
internal class SampleOCRCodeActivity : OCRCodeActivity
    {
        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(SampleOCRCodeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

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

        protected override Dictionary<string, object> BeforeExecute(CodeActivityContext context)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }[DisplayName("Sample OCRCodeActivity")]
internal class SampleOCRCodeActivity : OCRCodeActivity
    {
        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(SampleOCRCodeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

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

        protected override Dictionary<string, object> BeforeExecute(CodeActivityContext context)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }
  • Definition
  • Description
  • Members
  • Code Sample

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.