You are viewing limited content. For full access, please sign in.

Question

Question

OCR , Extract the text using c#.

asked on July 16, 2018 Show version history

Hi all,

I want to use workflow to perform OCR and extract the text. Any help on how I can achieve this, and especially help with the libraries needed and the laserfiche references.

Thanks Prudence,

 

 

0 0

Replies

replied on July 16, 2018 Show version history

First of all, the OCR process is a resource intense process, so it is not recommended that it be done from your main production Workflow Server.  So set up a new Workflow Server to run the OCR workflow.

That said...

Add reference for Laserfiche.DocumentServices and add the using statement at the top of the code.

Then in your Execute code block:

        protected override void Execute()
        {
            // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            string sError = "None";
            try
            {
                //  Retrieves a document to be processed with OCR.
                if ((BoundEntryInfo.EntryType == EntryType.Document))
                {
                    using (DocumentInfo Doc = (DocumentInfo)BoundEntryInfo)
                    {
                        Doc.Lock(LockType.Exclusive);
                        //  Instantiates a new OCR engine.
                        using (OcrEngine ocr = OcrEngine.LoadEngine())
                        {
                            //  configure OCR options
                            ocr.AutoOrient = true;
                            ocr.Decolumnize = true;
                            ocr.OptimizationMode = OcrOptimizationMode.Accuracy;
                            //  Generate text for all pages of the given document
                            PageSet ps = Doc.AllPages;
                            ocr.Run(Doc, ps);
                        }
                    //  unlock the document
                    Doc.Unlock();
                    }
                }
            }
            catch (Exception ex)
            {
                sError = ex.Message;
                WorkflowApi.TrackError(ex.Message);
            }
            SetTokenValue("Script_Error", sError);
        }

 

5 0
replied on July 16, 2018

Thank you very much Warren for the responsesmiley

replied on July 16, 2018

Though I think I might have asked my question the other way round.

 

replied on July 16, 2018

What do you mean that you may have asked the question the other way round?

You are not allowed to follow up in this post.

Sign in to reply to this post.