Beispiel #1
0
        private List <PdfTextInfo> GetBoundedTextInfo(double left, double top, double right, double bottom)
        {
            var boundedArea  = new FS_RECTF((float)left, (float)top, (float)right, (float)bottom);
            var textInfoList = new List <PdfTextInfo>();
            var allRects     = GetAllRects();

            GetAllCharInfo(); //Ensure char info is cached in memory

            foreach (var rect in allRects)
            {
                if (rect.IntersectsWith(boundedArea))
                {
                    // Find all the characters that fit in this rect AND the boundedArea
                    var chars     = _allCharInfo.FindAll(c => rect.Contains(c.BoundingRectangle) && boundedArea.ContainsPartially(c.BoundingRectangle, 50));
                    var charBoxes = new List <FS_RECTF>();
                    chars.ForEach(c => charBoxes.Add(c.BoundingRectangle));
                    var boundingRect = FS_RECTF.Union(charBoxes);

                    textInfoList.Add(new PdfTextInfo(string.Join <PdfTextInfo>(string.Empty, chars.ToArray()), -1, chars.Count, boundingRect, charBoxes));
                }
            }

            textInfoList.Sort((x, y) =>
            {
                // Sort top to bottom, left to right.
                int retval = -x.BoundingRectangle.Bottom.CompareTo(y.BoundingRectangle.Bottom);
                return(retval == 0 ? x.BoundingRectangle.Left.CompareTo(y.BoundingRectangle.Left) : retval);
            });

            return(textInfoList);
        }
Beispiel #2
0
            public void AddLine(PdfTextInfo line)
            {
                if (Lines.Any())
                {
                    BoundingRectangle = BoundingRectangle.Union(line.BoundingRectangle);
                }
                else
                {
                    BoundingRectangle = line.BoundingRectangle;
                }

                Lines.Add(line);
            }