示例#1
0
        public void Execute(Arguments arguments)
        {
            if ((arguments.Language?.Value == null) && (arguments.Dictionary?.Value == null))
            {
                arguments.Language = new TextStructure("English");
            }

            AbbyyManager manager = AbbyyManager.Instance;

            FineReaderDocument document = manager.CreateDocument(arguments.Path.Value);

            List <int> pageIndices = null;

            if (arguments.Pages != null && arguments.Pages.Value != null)
            {
                pageIndices = new List <int>(arguments.Pages.Value.Count);
                foreach (Structure o in arguments.Pages.Value)
                {
                    pageIndices.Add(((IntegerStructure)o).Value - 1);
                }
            }

            manager.ProcessDocument(document, pageIndices, arguments.Language?.Value, arguments.LanguageWeight.Value, arguments.DictionaryWeight.Value, ListConverter.ExtractDictionary(arguments.Dictionary?.Value));
            var a = document.Tables.Count;

            Scripter.Variables.SetVariableValue(arguments.Result.Value, new IntegerStructure(document.ID));
            Scripter.Variables.SetVariableValue(arguments.TablesCountResult.Value, new IntegerStructure(document.Tables.Count));
        }
        public void Execute(Arguments arguments)
        {
            manager = AbbyyManager.Instance;

            System.Drawing.Rectangle rectangle    = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates();
            System.Drawing.Bitmap    partOfScreen = RobotWin32.GetPartOfScreen(rectangle);

            IEngine engine = manager.Engine;
            DocumentProcessingParams processingParams  = engine.CreateDocumentProcessingParams();
            RecognizerParams         recognizingParams = processingParams.PageProcessingParams.RecognizerParams;

            recognizingParams.SetPredefinedTextLanguage(arguments.Language.Value);
            engine.LoadPredefinedProfile(AbbyyManager.TextAccuracyProfile);
            FRDocument imageDocument = engine.CreateFRDocument();

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                partOfScreen.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                stream.Position = 0;
                IReadStream imageStream = new StreamNet2AbbyyAdapter(stream);
                imageDocument.AddImageFileFromStream(imageStream);
            }

            imageDocument.Process(processingParams);


            Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(imageDocument.PlainText.Text));
        }
        public void Dispose()
        {
            foreach (FineReaderDocument doc in documents.Values)
            {
                try
                {
                    doc.Document.Close();
                }
                catch { }
            }

            try
            {
#if DEBUG
                long memorySizeBefore = GC.GetTotalMemory(false);
#endif
                lock (syncRoot)
                {
                    engine   = null;
                    instance = null;
                    engineLoader.ExplicitlyUnload();
                    engineLoader = null;
                    GC.Collect();
                    System.Threading.Thread.Sleep(1);
                    GC.WaitForPendingFinalizers();
                }
#if DEBUG
                long memorySizeAfter = GC.GetTotalMemory(false);
#endif
            }
            catch { }
        }
        public void Execute(Arguments arguments)
        {
            AbbyyManager       manager  = AbbyyManager.Instance;
            FineReaderDocument document = manager.GetDocument(manager.CurentDocumentCount);

            document.ExportToXml(arguments.Path.Value);
        }
示例#5
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager manager = AbbyyManager.Instance;
            int          docID   = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            var          doc     = manager.GetDocument(docID);

            Scripter.Variables.SetVariableValue(arguments.Result.Value, new AbbyyDocumentStructure(doc.CustomDocument));
        }
示例#6
0
        public void Execute(Arguments arguments)
        {
            manager = AbbyyManager.Instance;
            int           docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            var           doc   = manager.GetDocument(docID);
            List <string> table = doc.Tables[arguments.TableIndex.Value].ReturnWordPosition(arguments.Search.Value);
            ListStructure cells = new ListStructure(new List <Structure>());

            foreach (String t in table)
            {
                cells.Value.Add(new TextStructure(t));
            }
            Scripter.Variables.SetVariableValue(arguments.Result.Value, cells);
        }
        public void Execute(Arguments arguments)
        {
            manager = AbbyyManager.Instance;
            int docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            var doc   = manager.GetDocument(docID);

            List <Rectangle> rectangles = doc.FindPosition(arguments.Search.Value);

            ListStructure matchesRectangles = new ListStructure(new List <Structure>());

            foreach (Rectangle r in rectangles)
            {
                matchesRectangles.Value.Add(new RectangleStructure(r));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, matchesRectangles);
        }
示例#8
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager       manager  = AbbyyManager.Instance;
            int                docID    = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            FineReaderDocument document = manager.GetDocument(docID);

            document.ExtractData();
            List <FineReaderParagraph> paragraphs = document.Paragraphs;

            ListStructure paragraphsList = new ListStructure(new List <Structure>());

            foreach (FineReaderParagraph p in paragraphs)
            {
                paragraphsList.Value.Add(new TextStructure(p.Text));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, paragraphsList);
        }
示例#9
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager       manager  = AbbyyManager.Instance;
            int                docID    = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            FineReaderDocument document = manager.GetDocument(docID);
            int                row      = 0;
            int                column   = 0;

            string[] position = arguments.Position.Value.Split(',');

            row    = int.Parse(position[0]);
            column = int.Parse(position[1]);

            System.Drawing.Point cellSpans = new System.Drawing.Point(
                document.Tables[arguments.TableIndex.Value - 1][row - 1, column - 1].RowSpan,
                document.Tables[arguments.TableIndex.Value - 1][row - 1, column - 1].ColumnSpan);

            Scripter.Variables.SetVariableValue(arguments.Result.Value, new PointStructure(cellSpans));
        }
示例#10
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager manager = AbbyyManager.Instance;

            int docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;

            FineReaderDocument document = manager.GetDocument(docID);

            document.ExtractData();

            ListStructure cellsText = new ListStructure(new List <Structure>());

            foreach (FineReaderCell c in document.Cells)
            {
                cellsText.Value.Add(new TextStructure(c.Text));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, cellsText);
        }
        public void Execute(Arguments arguments)
        {
            AbbyyManager manager = AbbyyManager.Instance;
            int          docID   = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;
            var          doc     = manager.GetDocument(docID);
            string       output  = string.Empty;

            switch (arguments.Method.Value.ToLower())
            {
            case "structured":
                output = doc.GetAllText();
                break;

            case "linebyline":
                output = doc.GetLinesText();
                break;

            default:
                throw new ArgumentException("Wrong method argument. It accepts either 'structured' or 'linebyline' value.");
            }
            Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(output));
        }
示例#12
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager       manager      = AbbyyManager.Instance;
            int                docID        = arguments.DocumentID?.Value ?? manager.CurentDocumentCount;
            FineReaderDocument document     = manager.GetDocument(docID);
            int                row          = 0;
            int                column       = 0;
            int                rowOffset    = 0;
            int                columnOffset = 0;

            var position = arguments.Position.Value.Split(',');

            row    = int.Parse(position[0]);
            column = int.Parse(position[1]);

            if (!string.IsNullOrEmpty(arguments.Offset?.Value))
            {
                var positionOffset = arguments.Offset.Value.Split(',');
                rowOffset    = int.Parse(positionOffset[0]);
                columnOffset = int.Parse(positionOffset[1]);
            }

            string cellTextValue = string.Empty;

            try
            {
                cellTextValue = document.Tables[arguments.TableIndex.Value - 1][row - 1 + rowOffset, column - 1 + columnOffset].Text ?? string.Empty;
            }
            catch
            {
            }

            TextStructure cellText = new TextStructure(cellTextValue);

            Scripter.Variables.SetVariableValue(arguments.Result.Value, cellText);
        }
示例#13
0
        public void Execute(Arguments arguments)
        {
            AbbyyManager manager = AbbyyManager.Instance;

            FineReaderDocument.FilterFlags paramsFilter = FineReaderDocument.FilterFlags.none;

            string[] flagsString = arguments.Filter.Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string flag in flagsString)
            {
                FineReaderDocument.FilterFlags currentFlag = FineReaderDocument.FilterFlags.none;
                try
                {
                    currentFlag   = (FineReaderDocument.FilterFlags)Enum.Parse(typeof(FineReaderDocument.FilterFlags), flag.Trim(), true);
                    paramsFilter |= (FineReaderDocument.FilterFlags)Enum.Parse(typeof(FineReaderDocument.FilterFlags), flag.Trim(), true);
                }
                catch
                {
                    throw new ArgumentOutOfRangeException(nameof(arguments.Filter), currentFlag, $"{currentFlag} is not defined filter");
                }
            }

            int docID = arguments.DocumentID == null ? manager.CurentDocumentCount : arguments.DocumentID.Value;

            FineReaderDocument document = manager.GetDocument(docID);

            document.ExtractData();

            ListStructure filteredTexts = new ListStructure(new List <Structure>());

            foreach (string s in document.Filter(paramsFilter))
            {
                filteredTexts.Value.Add(new TextStructure(s));
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, filteredTexts);
        }
        public void Execute(Arguments arguments)
        {
            if ((arguments.Language?.Value == null) && (arguments.Dictionary?.Value == null))
            {
                arguments.Language = new TextStructure("English");
            }

            Rectangle rectangle    = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates();
            Bitmap    partOfScreen = RobotWin32.GetPartOfScreen(rectangle);

            AbbyyManager       manager       = AbbyyManager.Instance;
            FineReaderDocument imageDocument = null;

            using (MemoryStream stream = new MemoryStream())
            {
                partOfScreen.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                stream.Position = 0;
                imageDocument   = manager.CreateDocument(stream);
            }

            manager.ProcessDocument(imageDocument, null, arguments.Language?.Value, arguments.LanguageWeight.Value, arguments.DictionaryWeight.Value, ListConverter.ExtractDictionary(arguments.Dictionary?.Value));

            Scripter.Variables.SetVariableValue(arguments.Result.Value, new IntegerStructure(imageDocument.ID));
        }