public void Execute(Arguments arguments)
        {
            AbbyyManager       manager  = AbbyyManager.Instance;
            FineReaderDocument document = manager.GetDocument(manager.CurentDocumentCount);

            document.ExportToXml(arguments.Path.Value);
        }
示例#2
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));
        }
示例#3
0
        public void ProcessWithCustomDirectoryTest()
        {
            string        path  = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.document1), "tif");
            List <string> words = new List <string>
            {
                "inwestycje",
                "długoterminowe",
                "aktywa",
                "trwałe",
                "prac",
                "prawne",
                "pozostałych",
                "akcje",
                "papiery",
                "pożyczki",
                "podatku"
            };

            List <GStructures.Structure> wordsList = new List <GStructures.Structure>(words.Capacity);

            foreach (string word in words)
            {
                wordsList.Add(new GStructures.TextStructure(word));
            }

            scripter.InitVariables.Add(nameof(wordsList), new GStructures.ListStructure(wordsList));
            scripter.Text = ($"ocrabbyy.processfile {SpecialChars.Text}{path}{SpecialChars.Text} language Polish languageweight 0 dictionary {SpecialChars.Variable}{nameof(wordsList)}");
            scripter.Run();
            //scripter.RunLine($"ocrabbyy.processfile {SpecialChars.Text}{Initializer.BgzBilans6Path}{SpecialChars.Text} dictionary {SpecialChars.Variable}{nameof(wordsList)}");
            int documentId = scripter.Variables.GetVariableValue <int>("result");

            FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId);
        }
        public FineReaderDocument CreateDocument(string path)
        {
            FineReaderDocument document = CreateDocument();

            document.Document.AddImageFile(path, PrepareMode: prepareImageMode);

            return(document);
        }
        private FineReaderDocument CreateDocument()
        {
            FineReaderDocument document = new FineReaderDocument(engine.CreateFRDocument(), ++countID);

            documents[countID] = document;

            return(document);
        }
        public FineReaderDocument CreateDocument(Stream stream)
        {
            stream.Position = 0;
            IReadStream        abbyyStream = new StreamNet2AbbyyAdapter(stream);
            FineReaderDocument document    = CreateDocument();

            document.Document.AddImageFileFromStream(abbyyStream, PrepareMode: prepareImageMode);

            return(document);
        }
示例#7
0
        public void LanguageTest()
        {
            scripter.Text = ($"ocrabbyy.processfile {SpecialChars.Variable}file language Polish");
            scripter.Run();
            int documentId = scripter.Variables.GetVariableValue <int>("result");

            FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId);

            Assert.IsNotNull(document);
            string plainText = document.GetAllText();

            Assert.AreNotEqual(Properties.Resources.documentText, plainText);
        }
        public void CloseTest()
        {
            scripter.RunLine($@"ocrabbyy.processfile {SpecialChars.Variable}file result {SpecialChars.Variable}result1
                               ocrabbyy.processfile {SpecialChars.Variable}file
                               ocrabbyy.close");
            scripter.Run();
            int documentId = scripter.Variables.GetVariableValue <int>("result1");
            FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId);
            long engineLoadedMemory     = GetAllocatedMemory();
            long engineUnloadedMemory   = GetAllocatedMemory();

            Assert.IsTrue(engineLoadedMemory - engineUnloadedMemory > 0x10000, $"Closing engine relesed less than 1MB of memory, relesed bytes = {engineLoadedMemory - engineUnloadedMemory}");
        }
示例#9
0
        public void PagesTest()
        {
            string doc4Path       = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.dokument4), "pdf");
            string endOfFirstPage = @"Nowa sekcja 3 Strona 1";

            List <GStructures.Structure> list = new List <GStructures.Structure>()
            {
                new GStructures.IntegerStructure(1)
            };

            scripter.InitVariables.Add(nameof(list), new GStructures.ListStructure(list));
            scripter.Text = ($"ocrabbyy.processfile {SpecialChars.Text}{doc4Path}{SpecialChars.Text} pages {SpecialChars.Variable}{nameof(list)}");
            scripter.Run();
            FineReaderDocument document = AbbyyManager.Instance.GetDocument(scripter.Variables.GetVariableValue <int>("result"));

            Assert.IsTrue(document.GetAllText().Trim().EndsWith(endOfFirstPage));
        }
示例#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();
            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);
        }
        public void RelativeTest()
        {
            IntPtr hTesterAppWindow = testerApp.MainWindowHandle;

            RobotWin32.Rect windowRect = new RobotWin32.Rect();
            RobotWin32.GetWindowRectangle(hTesterAppWindow, ref windowRect);
            int titleBarHeight = 24;

            scripter.Text = ($"ocrabbyy.processscreen area {SpecialChars.Text}0,0,{windowRect.Right - windowRect.Left},{titleBarHeight}{SpecialChars.Text} relative true");
            scripter.Run();
            int documentId = scripter.Variables.GetVariableValue <int>("result");

            FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId);

            Assert.IsNotNull(document);
            string plainText = document.GetAllText();

            Assert.IsTrue(plainText.Contains(appTitle));
        }
        public void ProcessDocument(FineReaderDocument document, List <int> pageIndices, string language, int languageWeight, int dictionaryWeight, List <string> dictionary = null, SettingsMode mode = SettingsMode.None)
        {
            document.Document.Preprocess();
            if (pageIndices == null)
            {
                document.Document.Process(GetProcessingParameters(language, mode, dictionary, languageWeight, dictionaryWeight));
            }
            else
            {
                IntsCollection indices = engine.CreateIntsCollection();
                foreach (int i in pageIndices)
                {
                    indices.Add(i);
                }

                document.Document.ProcessPages(indices, GetProcessingParameters(language, mode, dictionary, languageWeight, dictionaryWeight));
            }
            document.InitializeCustomDocument();
        }
示例#13
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));
        }
示例#14
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 CloseDocumentTest()
        {
            scripter.RunLine($@"ocrabbyy.processfile {SpecialChars.Variable}file language English result {SpecialChars.Variable}result1
                                ocrabbyy.processfile {SpecialChars.Variable}file language English result {SpecialChars.Variable}result2");
            int documentId = scripter.Variables.GetVariableValue <int>("result1");
            FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId);

            int document2Id = scripter.Variables.GetVariableValue <int>("result2");
            FineReaderDocument document2 = AbbyyManager.Instance.GetDocument(document2Id);

            scripter.Text = ($"ocrabbyy.close {document2Id}");
            scripter.Run();
            document.ExtractData();
            bool isDocumentClosed = false;

            try
            {
                document2.ExtractData();
            }
            catch
            {
                isDocumentClosed = true;
            }
            Assert.IsTrue(isDocumentClosed);

            scripter.Text = ($"ocrabbyy.close {documentId}");
            scripter.Run();
            isDocumentClosed = false;
            try
            {
                document.ExtractData();
            }
            catch
            {
                isDocumentClosed = true;
            }
            Assert.IsTrue(isDocumentClosed);
        }
        public void LanguageTest()
        {
            IntPtr hTesterAppWindow = testerApp.MainWindowHandle;

            RobotWin32.Rect windowRect = new RobotWin32.Rect();
            RobotWin32.GetWindowRectangle(hTesterAppWindow, ref windowRect);
            int titleBarHeight = 24;

            string appTitle2 = "шестьсот";  // in case someone worry what this mean, it's six hundred

            scripter.Text = ($@"keyboard {SpecialChars.Text}title {appTitle2}{SpecialChars.Text}{SpecialChars.KeyBegin}enter{SpecialChars.KeyEnd}
                                ocrabbyy.processscreen area {SpecialChars.Text}{windowRect.Left},{windowRect.Top},{windowRect.Right},{windowRect.Top + titleBarHeight}{SpecialChars.Text} language russian");
            scripter.Run();

            int documentId = scripter.Variables.GetVariableValue <int>("result");

            FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId);

            Assert.IsNotNull(document);
            string plainText = document.GetAllText();

            Assert.IsTrue(plainText.Contains(appTitle2));
        }
        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));
        }
示例#18
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);
        }
示例#19
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);
        }