예제 #1
0
        /// <summary>
        /// Devuelve un patrón de búsqueda a partir de la
        /// instancia de coicidencia.
        /// </summary>
        /// <returns>Patrón de búsqueda.</returns>
        public PdfTagPattern GetPdfTagPattern()
        {
            PdfTextBaseRectangle rectangle = null;

            if (_PdfTextRectangle != null)
            {
                rectangle = new PdfTextBaseRectangle()
                {
                    Llx = _PdfTextRectangle.Llx,
                    Lly = _PdfTextRectangle.Lly,
                    Urx = _PdfTextRectangle.Urx,
                    Ury = _PdfTextRectangle.Ury
                }
            }
            ;
            else if (_PdfColorFontTextRectangle != null)
            {
                rectangle = new PdfTextBaseRectangle()
                {
                    Llx = _PdfColorFontTextRectangle.Llx,
                    Lly = _PdfColorFontTextRectangle.Lly,
                    Urx = _PdfColorFontTextRectangle.Urx,
                    Ury = _PdfColorFontTextRectangle.Ury
                };
            }


            string regexPattern = _TextMatch.Pattern ??
                                  TxtRegex.Replace(_TextMatch.TextValue);


            if (_PdfColorFontTextRectangle != null)
            {
                return new PdfTagPattern()
                       {
                           RegexPattern     = regexPattern,
                           Position         = _TextMatch.Position,
                           PdfPageN         = PdfPageN,
                           PdfRectangle     = rectangle,
                           MetadataItemName = MetadataItemName,
                           FillColor        = _PdfColorFontTextRectangle.FillColor,
                           StrokeColor      = _PdfColorFontTextRectangle.StrokeColor,
                           FontName         = _PdfColorFontTextRectangle.FontName,
                           FontSize         = _PdfColorFontTextRectangle.FontSize.ToString(),
                           CFType           = _PdfColorFontTextRectangle.Type
                       }
            }
            ;
            else
            {
                return new PdfTagPattern()
                       {
                           RegexPattern     = regexPattern,
                           Position         = _TextMatch.Position,
                           PdfPageN         = PdfPageN,
                           PdfRectangle     = rectangle,
                           MetadataItemName = MetadataItemName,
                       }
            };
        }
        /// <summary>
        /// Devuelve el coeficiente calculado como la división del área
        /// del rectángulo intersección con el área del rectángulo facilitado
        /// como primero parámetro (first) que se debe corresponder con
        /// un rectángulo procedente de las colecciones WordGroups o Lines
        /// de una página que se están comparando con el rectángulo primero (first)
        /// el cual proviene de un patrón almacenado.
        /// </summary>
        /// <returns>Coeficiente de área del rectángulo first contenido
        /// en el rectangulo second. Un valor
        /// de 1 significa el rectángulo first está totalmente contenido
        /// en second.</returns>
        private float GetCommonAreaCoef(PdfTextBaseRectangle first,
                                        PdfTextBaseRectangle second)
        {
            iTextSharp.text.Rectangle firstRect = new iTextSharp.text.Rectangle(first.Llx,
                                                                                first.Lly, first.Urx, first.Ury);

            iTextSharp.text.Rectangle secondRect = new iTextSharp.text.Rectangle(second.Llx,
                                                                                 second.Lly, second.Urx, second.Ury);

            iTextSharp.text.Rectangle intersectRect = PdfTextBaseRectangle.Intersect(firstRect, secondRect);

            if (intersectRect == null)
            {
                return(0);
            }

            float firstRectArea     = PdfTextBaseRectangle.GetArea(firstRect);
            float intersectRectArea = PdfTextBaseRectangle.GetArea(intersectRect);

            return(intersectRectArea / firstRectArea);
        }
예제 #3
0
 /// <summary>
 /// Devuelve true si los rectángulos comparten
 /// un área superior a la establecidad en las
 /// opciones de configuración.
 /// </summary>
 /// <param name="first">Rectángulo 1.</param>
 /// <param name="second">Rectángulo 2.</param>
 /// <returns>True si comparten suficiente área
 /// para considerarse como similares.</returns>
 private bool IsAlmostSameArea(PdfTextBaseRectangle first,
                               PdfTextBaseRectangle second)
 {
     return(GetCommonAreaCoef(first, second) >
            Settings.Current.MinRectangleCommon);
 }
예제 #4
0
        /// <summary>
        /// Devuelve un patrón de búsqueda a partir de la
        /// instancia de coicidencia.
        /// </summary>
        /// <returns>Patrón de búsqueda.</returns>
        public PdfTagPattern GetPdfTagPattern()
        {
            PdfTextBaseRectangle rectangle = null;

            string colorStroke = null;
            string colorFill   = null;
            string fontType    = null;
            string fontSize    = null;
            string type        = null;
            string coordinate  = null;

            if (_PdfClownTextString == null)
            {
                if (_PdfTextRectangle != null)
                {
                    rectangle = new PdfTextBaseRectangle()
                    {
                        Llx = _PdfTextRectangle.Llx,
                        Lly = _PdfTextRectangle.Lly,
                        Urx = _PdfTextRectangle.Urx,
                        Ury = _PdfTextRectangle.Ury
                    }
                }
                ;
            }
            else
            {
                try
                {
                    colorStroke = _PdfClownTextString.ColorStroke.BaseDataObject.ToString();
                    colorFill   = _PdfClownTextString.ColorFill.BaseDataObject.ToString();
                    fontSize    = _PdfClownTextString.FontSize.ToString();
                    fontType    = _PdfClownTextString.FontType.Name;
                    type        = _PdfClownTextString.Type;
                    if (_PdfClownTextString.Rectangle != null)
                    {
                        RectangleF?rect = _PdfClownTextString.Rectangle;
                        if (type.Equals("X"))
                        {
                            coordinate = _PdfClownTextString.Rectangle.Value.X.ToString();
                        }
                        else if (type.Equals("Y"))
                        {
                            coordinate = _PdfClownTextString.Rectangle.Value.Y.ToString();
                        }
                    }
                }
                catch
                {
                }
            }

            string regexPattern = _TextMatch.Pattern ??
                                  TxtRegex.Replace(_TextMatch.TextValue);

            return(new PdfTagPattern()
            {
                RegexPattern = regexPattern,
                Position = _TextMatch.Position,
                IsLastPage = (PdfPageN == _Pdf.PdfUnstructuredPages.Count),
                PdfPageN = PdfPageN,
                PdfRectangle = rectangle,
                MetadataItemName = MetadataItemName,
                ColorFill = colorFill,
                ColorStroke = colorStroke,
                FontSize = fontSize,
                FontType = fontType,
                TsType = type,
                TsCoordinate = coordinate
            });
        }