Exemple #1
0
        public void OcrAbbyyGetDocument1Test()
        {
            scripter.Text = $@"ocrabbyy.processfile path {SpecialChars.Variable}file
                            ocrabbyy.getdocument result {SpecialChars.Text}document{SpecialChars.Text}
                            {SpecialChars.Variable}pagesCount = {SpecialChars.Variable}document{SpecialChars.IndexBegin}count{SpecialChars.IndexEnd}
                            {SpecialChars.Variable}firstPage = {SpecialChars.Variable}document{SpecialChars.IndexBegin}0{SpecialChars.IndexEnd}
                            {SpecialChars.Variable}rowsCount = {SpecialChars.Variable}firstpage{SpecialChars.IndexBegin}count{SpecialChars.IndexEnd}
                            {SpecialChars.Variable}tenthRow = {SpecialChars.Variable}firstPage{SpecialChars.IndexBegin}9{SpecialChars.IndexEnd}
                            {SpecialChars.Variable}cellsCount = {SpecialChars.Variable}tenthRow{SpecialChars.IndexBegin}count{SpecialChars.IndexEnd}";

            scripter.Run();
            CustomRow row = scripter.Variables.GetVariableValue <CustomRow>("tenthRow");

            Assert.IsNotNull(row);
            Assert.IsTrue(row.Cells.Count == 4);
            Assert.AreEqual("4", row.Cells[0].Text);
            Assert.IsTrue(row.Cells[1].Text.ToLower().Contains("zaliczki"));
            Assert.AreEqual("0,00", row.Cells[2].Text.Replace(".", ","));
            Assert.AreEqual("0,00", row.Cells[3].Text.Replace(".", ","));
        }
        private CustomBlock buildTextFromBlock(FREngine.IBlock block, int iBlock)
        {
            if (block.Type == FREngine.BlockTypeEnum.BT_Table)
            {
                FREngine.ITableBlock tableBlock = block.GetAsTableBlock();

                CustomTable cstable = new CustomTable();

                cstable.X           = tableBlock.Region.BoundingRectangle.Left;
                cstable.Y           = tableBlock.Region.BoundingRectangle.Top;
                cstable.Width       = tableBlock.Region.BoundingRectangle.Width;
                cstable.Height      = tableBlock.Region.BoundingRectangle.Height;
                cstable.ParentIndex = Page.Index;
                cstable.Index       = tableIndex;
                tableIndex++;

                List <CustomBlock> blockItems = new List <CustomBlock>();

                for (int iCell = 0; iCell < tableBlock.Cells.Count; iCell++)
                {
                    FREngine.ITableCell cell    = tableBlock.Cells[iCell];
                    CustomBlock         csBlock = buildTextFromBlock(cell.Block, iCell);
                    if (csBlock != null)
                    {
                        blockItems.Add(csBlock);
                        //blockAll.Add(csBlock);
                    }
                }
                var rowItemsGroup = blockItems.GroupBy(x => x.Y);

                int iRow = 0;
                foreach (var item in rowItemsGroup)
                {
                    CustomRow rowItem = new CustomRow()
                    {
                        Width       = cstable.Width,
                        Height      = item.Max(x => x.Height),
                        BlockItems  = item.ToList(),
                        X           = item.Min(x => x.X),
                        Y           = item.Min(x => x.Y),
                        Value       = string.Join("\t", item.Select(x => x.Value)),
                        Index       = iRow,
                        ParentIndex = iBlock,
                    };
                    cstable.RowItems.Add(rowItem);
                    iRow++;
                }



                cstable.Value = string.Join("\n", cstable.RowItems.Select(x => x.Value));; //
                //string.Join("|", cstable.BlockItems.Select(x => x.Value));
                Page.TableItems.Add(cstable);
                return(null);
            }

            if (block.Type != FREngine.BlockTypeEnum.BT_Text)
            {
                return(null);
            }

            CustomBlock result = new CustomBlock();

            FREngine.ITextBlock textBlock = block.GetAsTextBlock();

            result.Index  = iBlock;
            result.X      = textBlock.Region.BoundingRectangle.Left;
            result.Y      = textBlock.Region.BoundingRectangle.Top;
            result.Width  = textBlock.Region.BoundingRectangle.Width;
            result.Height = textBlock.Region.BoundingRectangle.Height;


            for (int iPar = 0; iPar < textBlock.Text.Paragraphs.Count; iPar++)
            {
                FREngine.IParagraph par = textBlock.Text.Paragraphs[iPar];
                result.LineItems.AddRange(buildTextFromParagraph(par, iBlock));
            }

            result.Value = string.Join("\n", result.LineItems.Select(x => x.Value));

            return(result);
        }