Ejemplo n.º 1
0
        public List <TablePos> GetOnlyTablePos(string tableName, LocateConfiguration locateConfiguration, bool isChineseTableName)
        {
            List <TablePos> tablePoses = new List <TablePos>();
            LinePos         linePos    = null;

            _locateConfiguration = locateConfiguration;

            LinePos tableNamePos = GetSearchTextResult(tableName, tableName, ref linePos, true);

            if (tableNamePos == null)
            {
                linePos      = null;
                tableNamePos = GetSearchTextResult(tableName.GetFirstLetter(isChineseTableName), tableName, ref linePos, true);
            }
            if (tableNamePos != null)
            {
                string  tableEndRegex            = locateConfiguration.TableEndRegex;
                string  tableEndFirstLetterRegex = locateConfiguration.TableEndFirstLetterRegex;
                LinePos tableEndPos = GetSearchTextResult(tableEndRegex, tableEndRegex, ref linePos, false);
                if (tableEndPos == null)
                {
                    linePos     = null;
                    tableEndPos = GetSearchTextResult(tableEndFirstLetterRegex, tableEndRegex, ref linePos, false);
                }
                if (tableEndPos == null)
                {
                    tableEndPos = pdfTronHelper.GetBottomPosOfPage(tableNamePos.PageNum, false, -1, -1);
                }
                tablePoses = GetTablePoses(tableNamePos, tableEndPos);
            }
            return(tablePoses);
        }
Ejemplo n.º 2
0
        public int CompareTo(object obj)
        {
            LinePos linePos = obj as LinePos;

            if (PageNum < linePos.PageNum)
            {
                return(-1);
            }

            if (PageNum == linePos.PageNum)
            {
                if (AxisValue == linePos.AxisValue)
                {
                    return(0);
                }

                return(AxisValue < linePos.AxisValue ? 1 : -1);
            }

            if (PageNum > linePos.PageNum)
            {
                return(1);
            }

            return(0);
        }
Ejemplo n.º 3
0
        private LinePos GetSearchTextResult(string searchText, string verifyText, ref LinePos lowRange, bool isTableName)
        {
            try
            {
                bool isDone    = false;
                int  startPage = pdfTronHelper.GetLowPage(lowRange);
                while (!isDone)
                {
                    List <LinePos> linePoses = pdfTronHelper.Search(searchText, lowRange, null, ref startPage);
                    if (linePoses.Count > 0)
                    {
                        foreach (LinePos linePos in linePoses)
                        {
                            if (!Regex.IsMatch(linePos.TrimText, verifyText))
                            {
                                continue;
                            }

                            if (isTableName)
                            {
                                string  tableNameNearbyRegex            = _locateConfiguration.TableNameNearbyRegex;
                                string  tableNameNearbyFirstLetterRegex = _locateConfiguration.TableNameNearbyFirstLetterRegex;
                                LinePos linePosCopy           = (LinePos)linePos.Clone();
                                string  nearByRegexExpression = tableNameNearbyRegex;
                                LinePos tableNearbyPos        = GetSearchTextResult(nearByRegexExpression, nearByRegexExpression, ref linePosCopy, false);
                                if (tableNearbyPos == null)
                                {
                                    LinePos lowRangeCopy2 = (LinePos)linePos.Clone();
                                    tableNearbyPos = GetSearchTextResult(tableNameNearbyFirstLetterRegex, nearByRegexExpression, ref lowRangeCopy2, false);
                                }
                                if (tableNearbyPos == null || !ValidateTableNameNearbyPos(linePos, tableNearbyPos))
                                {
                                    continue;
                                }
                            }

                            lowRange = new LinePos()
                            {
                                PageNum   = linePos.PageNum,
                                AxisValue = linePos.AxisValue + GetError(true, linePos.PageNum),
                                TrimText  = linePos.TrimText
                            };

                            linePos.AxisValue = linePos.AxisValueWithLineHeight;
                            return(linePos);
                        }
                    }
                    isDone = startPage > pdfDoc.GetPageCount();
                }
            }
            catch (Exception ex)
            {
                string err = ex.ToString();
                throw;
            }

            return(null);
        }
Ejemplo n.º 4
0
        public List <TablePos> GetMultiTablePos(string tableName, LocateConfiguration locateConfiguration)
        {
            List <TablePos> tablePoses = new List <TablePos>();

            _locateConfiguration = locateConfiguration;
            LinePos        linePos        = null;
            List <LinePos> tableNamePoses = new List <LinePos>();
            List <LinePos> tableEndPoses  = new List <LinePos>();
            LinePos        tableNamePos   = null;

            do
            {
                LinePos linePosCopy = linePos == null ? null : (LinePos)linePos.Clone();
                tableNamePos = GetSearchTextResult(tableName, tableName, ref linePos, true);
                if (tableNamePos == null)
                {
                    linePos      = linePosCopy;
                    tableNamePos = GetSearchTextResult(tableName.GetFirstLetter(true), tableName, ref linePos, true);
                }
                if (tableNamePos != null)
                {
                    string tableEndRegex            = locateConfiguration.TableEndRegex;
                    string tableEndFirstLetterRegex = locateConfiguration.TableEndFirstLetterRegex;
                    linePosCopy = linePos == null ? null : (LinePos)linePos.Clone();
                    LinePos tableEndPos = GetSearchTextResult(tableEndRegex, tableEndRegex, ref linePos, false);
                    if (tableEndPos == null)
                    {
                        linePos     = linePosCopy;
                        tableEndPos = GetSearchTextResult(tableEndFirstLetterRegex, tableEndRegex, ref linePos, false);
                    }
                    if (tableEndPos == null)
                    {
                        tableEndPos = pdfTronHelper.GetBottomPosOfPage(tableNamePos.PageNum, false, -1, -1);
                    }
                    tableNamePoses.Add(tableNamePos);
                    tableEndPoses.Add(tableEndPos);
                }
                else
                {
                    break;
                }
            } while (tableNamePos != null);

            for (int i = 0; i < tableNamePoses.Count; i++)
            {
                List <TablePos> tempPoses = GetTablePoses(tableNamePoses[i], tableEndPoses[i]);
                tablePoses.AddRange(tempPoses);
            }

            return(tablePoses);
        }
Ejemplo n.º 5
0
        private List <TablePos> GetTablePoses(LinePos tableNamePos, LinePos tableEndPos)
        {
            List <TablePos> tablePoses = new List <TablePos>();

            tableNamePos.AxisValue = tableNamePos.AxisValueWithLineHeight;
            //There is only one page
            if (tableEndPos.PageNum == tableNamePos.PageNum)
            {
                TablePos tablePos = GetTablePos(tableNamePos.PageNum, tableNamePos, tableEndPos, false, false, null);
                if (tablePos != null)
                {
                    tablePoses.Add(tablePos);
                }
            }
            //The page amount is over one
            else
            {
                //Get start page
                //Mark
                TablePos startTablePos = null;
                LinePos  endPos        = pdfTronHelper.GetBottomPosOfPage(tableNamePos.PageNum, false, -1, -1);

                startTablePos = GetTablePos(tableNamePos.PageNum, tableNamePos, endPos, false, false, null);

                if (startTablePos != null)
                {
                    tablePoses.Add(startTablePos);
                }
                bool isStartTablePosNull = startTablePos == null;
                //Get medial page
                for (int i = tableNamePos.PageNum + 1; i < tableEndPos.PageNum; i++)
                {
                    TablePos intervalTablePos = GetTablePos(i, null, pdfTronHelper.GetBottomPosOfPage(i, false, -1, -1),
                                                            false,
                                                            !isStartTablePosNull, isStartTablePosNull ? null : startTablePos.VerticalLines);
                    if (intervalTablePos != null)
                    {
                        tablePoses.Add(intervalTablePos);
                    }
                }
                //Get end page
                int      endPageNum  = tableEndPos.PageNum;
                TablePos endTablePos = GetTablePos(endPageNum, null, tableEndPos, true,
                                                   !isStartTablePosNull, isStartTablePosNull ? null : startTablePos.VerticalLines);
                if (endTablePos != null)
                {
                    tablePoses.Add(endTablePos);
                }
            }
            return(tablePoses);
        }
Ejemplo n.º 6
0
        private TablePos GetTablePos(int pageNum, LinePos startPos, LinePos endPos, bool isEndTablePos, bool isSubsequentPage, SortedDictionary <double, FormLineList> lastPageVerticalLines)
        {
            FormLineSearcher searcher = new FormLineSearcher(pdfDoc);

            if (endPos != null)
            {
                endPos.AxisValue = endPos.AxisValueWithLineHeight;
            }
            SortedDictionary <double, FormLineList>[] formLines = searcher.GetFormLines(pageNum, startPos, endPos, isSubsequentPage, lastPageVerticalLines);
            if (formLines == null)
            {
                return(null);
            }
            TablePos tablePos;

            tablePos = new TablePos
            {
                PageNum          = pageNum,
                HorizontialLines = formLines[0],
                VerticalLines    = formLines[1]
            };
            //RevertAxisTransform(tablePos);
            return(tablePos);
        }
Ejemplo n.º 7
0
 public bool IsBetween(LinePos lowRange, LinePos maxRange)
 {
     return((lowRange == null || this > lowRange) &&
            (maxRange == null || this < maxRange));
 }
Ejemplo n.º 8
0
 private bool ValidateTableNameUnitInstance(LinePos tableNamePos, LinePos unitPos)
 {
     return(pdfTronHelper.ValidateInstance(tableNamePos, unitPos, maxInstance_Between_TableName_And_TabelNameNearbyInfo));
 }
Ejemplo n.º 9
0
 private bool ValidateTableNameNearbyPos(LinePos tableNamePos, LinePos nearbyPos)
 {
     return(nearbyPos != null && ValidateTableNameUnitInstance(tableNamePos, nearbyPos));
 }