/// Captures text using a simplified algorithm for inserting hard returns and spaces
 ///             @param   renderInfo  render info
 public virtual void RenderText(TextRenderInfo renderInfo)
 {
     _blocks.Add(new TextBlock
     {
         Text = renderInfo.GetText(),
         TopLeft = renderInfo.GetBaseline().GetStartPoint(),
         BottomRight = renderInfo.GetBaseline().GetEndPoint()
     });
 }
예제 #2
1
 /** 
  * @see com.itextpdf.text.pdf.parser.RenderFilter#allowText(com.itextpdf.text.pdf.parser.TextRenderInfo)
  */
 public override bool AllowText(TextRenderInfo renderInfo){
     LineSegment segment = renderInfo.GetBaseline();
     Vector startPoint = segment.GetStartPoint();
     Vector endPoint = segment.GetEndPoint();
     
     float x1 = startPoint[Vector.I1];
     float y1 = startPoint[Vector.I2];
     float x2 = endPoint[Vector.I1];
     float y2 = endPoint[Vector.I2];
     
     return filterRect.IntersectsLine(x1, y1, x2, y2);
 }
예제 #3
0
 /**
  * Used for creating sub-TextRenderInfos for each individual character
  * @param parent the parent TextRenderInfo
  * @param string the content of a TextRenderInfo
  * @param horizontalOffset the unscaled horizontal offset of the character that this TextRenderInfo represents
  * @since 5.3.3
  */
 private TextRenderInfo(TextRenderInfo parent, PdfString @string, float horizontalOffset)
 {
     this.@string = @string;
     this.textToUserSpaceTransformMatrix = new Matrix(horizontalOffset, 0).Multiply(parent.textToUserSpaceTransformMatrix);
     this.gs = parent.gs;
     this.markedContentInfos = parent.markedContentInfos;
 }
예제 #4
0
 /// <summary>
 /// Determines the color that will mark the text snippet based on the
 /// position of the snippet (in case it's an artifact) or it's style
 /// (font name and size).
 /// </summary>
 /// <param name="textRenderInfo">the TextRenderInfo object</param>
 /// <param name="top">the Y position of the top margin</param>
 /// <returns>a color that will be used to mark the text snippet</returns>
 static BaseColor GetColor(TextRenderInfo textRenderInfo, float top)
 {
     if (textRenderInfo.GetBaseline().GetStartPoint()[1] > top)
         return artifactColor;
     TextStyle ts = new TextStyle(textRenderInfo);
     return textStyles[ts];
 }
예제 #5
0
        //This is called whenever a run of text is encountered
        public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {
            //This code assumes that if the baseline changes then we're on a newline
            Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();

            //See if the baseline has changed
            if ((this.lastBaseLine != null && this.lastEndLine != null) && ((Math.Abs(curBaseline[Vector.I2] - lastBaseLine[Vector.I2]) > 1) || Math.Abs(lastEndLine[Vector.I1] - curBaseline[Vector.I1]) > 10))
            {
                //See if we have text and not just whitespace
                if ((!String.IsNullOrWhiteSpace(this.result.ToString())))
                {
                    //Mark the previous line as done by adding it to our buffers
                    this.baselines.Add(this.lastBaseLine[Vector.I2]);
                    this.strings.Add(this.result.ToString());
                    var coor = new Tuple <float, float, string>(this.lastBaseLine[Vector.I1], this.lastBaseLine[Vector.I2], this.result.ToString());
                    coordinates.Add(coor);
                }
                //Reset our "line" buffer
                this.result.Clear();
            }

            //Append the current text to our line buffer
            this.result.Append(renderInfo.GetText());

            //Reset the last used line
            this.lastBaseLine = curBaseline;
            this.lastEndLine  = renderInfo.GetBaseline().GetEndPoint();
        }
 /**
  * Used for creating sub-TextRenderInfos for each individual character
  * @param parent the parent TextRenderInfo
  * @param charIndex the index of the character that this TextRenderInfo will represent
  * @param horizontalOffset the unscaled horizontal offset of the character that this TextRenderInfo represents
  * @since 5.3.3
  */
 private TextRenderInfo(TextRenderInfo parent, int charIndex, float horizontalOffset)
 {
     this.text = parent.text.Substring(charIndex, 1);
     this.textToUserSpaceTransformMatrix = new Matrix(horizontalOffset, 0).Multiply(parent.textToUserSpaceTransformMatrix);
     this.gs = parent.gs;
     this.markedContentInfos = parent.markedContentInfos;
 }
예제 #7
0
 /**
  * Applies filters, then delegates to the deleg if all filters pass
  * @param renderInfo contains info to render text
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
  */
 public void RenderText(TextRenderInfo renderInfo) {
     foreach (RenderFilter filter in filters) {
         if (!filter.AllowText(renderInfo))
             return;
     }
     deleg.RenderText(renderInfo);
 }
예제 #8
0
        //This is called whenever a run of text is encountered
        public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {
            //This code assumes that if the baseline changes then we're on a newline
            Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();

            //See if the baseline has changed
            if ((this._lastBaseLine != null) && (curBaseline[Vector.I2] != _lastBaseLine[Vector.I2]))
            {
                //See if we have text and not just whitespace
                if ((!String.IsNullOrWhiteSpace(this._result.ToString())))
                {
                    //Mark the previous line as done by adding it to our buffers
                    this._baselines.Add(this._lastBaseLine[Vector.I2]);
                    this._strings.Add(this._result.ToString());
                }

                //Reset our "line" buffer
                this._result.Clear();
            }

            //Append the current text to our line buffer
            this._result.Append(renderInfo.GetText());

            //Reset the last used line
            this._lastBaseLine = curBaseline;
        }
예제 #9
0
        /**
         *
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        public void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment  = renderInfo.GetBaseline();
            TextChunk   location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth());

            locationalResult.Add(location);
        }
예제 #10
0
        public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {
            //to check the components , you can use to print line by line
            //DataModel dataModel = new DataModel(); //1.1.18
            string curDataItself = renderInfo.GetText();
            //Console.WriteLine(curDataItself);
            string curDataFontStyle = "";
            string curFont          = renderInfo.GetFont().PostscriptFontName; // http://itextsupport.com/apidocs/itext5/5.5.9/com/itextpdf/text/pdf/parser/TextRenderInfo.html#getFont--

            if ((renderInfo.GetTextRenderMode() == 2 /*(int)TextRenderMode.FillThenStrokeText*/))
            {
                curDataFontStyle = "BOLD";

                curFont += "-Bold";
            }

            //This code assumes that if the baseline changes then we're on a newline
            Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
            Vector topRight    = renderInfo.GetAscentLine().GetEndPoint();

            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
            Single curFontSize             = rect.Height;

            //dataModel.fontSize = curFontSize;


            if (lastBaseLine != null && lastBaseLine[Vector.I2] != curBaseline[Vector.I2])
            {
                DataModel aDataModel = new DataModel();
                aDataModel.dataItself    = lastDataItself;
                aDataModel.fontSize      = lastFontSize;
                aDataModel.dataFontStyle = lastDataFontStyle;
                aDataModel.fontName      = lastFont;
                listOfData.Add(aDataModel);


                lastDataItself    = curDataItself;
                lastFont          = curFont;
                lastDataFontStyle = curDataFontStyle;
                lastFontSize      = curFontSize;
            }
            else
            {
                lastDataItself   += curDataItself;
                lastFont          = curFont;
                lastFontSize      = curFontSize;
                lastDataFontStyle = curDataFontStyle;
            }

            if (lastBaseLine == null)
            {
                lastDataItself    = curDataItself;
                lastFont          = curFont;
                lastFontSize      = curFontSize;
                lastDataFontStyle = curDataFontStyle;
            }

            this.lastBaseLine = curBaseline;
        }
예제 #11
0
        /**
         * Displays text.
         * @param string    the text to display
         */
        private void DisplayPdfString(PdfString str)
        {
            TextRenderInfo renderInfo = new TextRenderInfo(str, Gs(), textMatrix, markedContentStack);

            renderListener.RenderText(renderInfo);

            textMatrix = new Matrix(renderInfo.GetUnscaledWidth(), 0).Multiply(textMatrix);
        }
예제 #12
0
        /**
         * Method invokes by the PdfContentStreamProcessor.
         * Passes a TextRenderInfo for every text chunk that is encountered.
         * We'll use this object to obtain coordinates.
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        virtual public void RenderText(TextRenderInfo renderInfo) {
            if (textRectangle == null)
                textRectangle = renderInfo.GetDescentLine().GetBoundingRectange();
            else
                textRectangle.Add(renderInfo.GetDescentLine().GetBoundingRectange());
            
            textRectangle.Add(renderInfo.GetAscentLine().GetBoundingRectange());

        }
        /**
         * Captures text using a simplified algorithm for inserting hard returns and spaces
         * @param   renderInfo  render info
         */
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            bool firstRender = result.Length == 0;
            bool hardReturn  = false;

            LineSegment segment = renderInfo.GetBaseline();
            Vector      start   = segment.GetStartPoint();
            Vector      end     = segment.GetEndPoint();

            if (!firstRender)
            {
                Vector x0 = start;
                Vector x1 = lastStart;
                Vector x2 = lastEnd;

                // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
                float dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared;

                float sameLineThreshold = 1f; // we should probably base this on the current font metrics, but 1 pt seems to be sufficient for the time being
                if (dist > sameLineThreshold)
                {
                    hardReturn = true;
                }

                // Note:  Technically, we should check both the start and end positions, in case the angle of the text changed without any displacement
                // but this sort of thing probably doesn't happen much in reality, so we'll leave it alone for now
            }

            if (hardReturn)
            {
                //System.out.Println("<< Hard Return >>");
                AppendTextChunk('\n');
            }
            else if (!firstRender)
            {
                if (result[result.Length - 1] != ' ' && renderInfo.GetText().Length > 0 && renderInfo.GetText()[0] != ' ') // we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
                {
                    float spacing = lastEnd.Subtract(start).Length;
                    if (spacing > renderInfo.GetSingleSpaceWidth() / 2f)
                    {
                        AppendTextChunk(' ');
                        //System.out.Println("Inserting implied space before '" + renderInfo.GetText() + "'");
                    }
                }
            }
            else
            {
                //System.out.Println("Displaying first string of content '" + text + "' :: x1 = " + x1);
            }

            //System.out.Println("[" + renderInfo.GetStartPoint() + "]->[" + renderInfo.GetEndPoint() + "] " + renderInfo.GetText());
            AppendTextChunk(renderInfo.GetText());

            lastStart = start;
            lastEnd   = end;
        }
예제 #14
0
 /// <summary>
 /// Creates a TextStyle object by getting the font name and font size
 /// from a TextRenderInfo object.
 /// </summary>
 /// <param name="textRenderInfo">Object that contains info about a text snippet</param>
 public TextStyle(TextRenderInfo textRenderInfo)
 {
     String font = textRenderInfo.GetFont().FullFontName[0][3];
     if (font.Contains("+"))
         font = font.Substring(font.IndexOf("+") + 1, font.Length - font.IndexOf("+") - 1);
     if (font.Contains("-"))
         font = font.Substring(0, font.IndexOf("-"));
     this.fontName = font;
     this.fontSize = textRenderInfo.GetAscentLine().GetStartPoint()[1] - textRenderInfo.GetDescentLine().GetStartPoint()[1];
 }
 /// <summary>
 /// <see cref="IRenderListener.RenderText"/>
 /// </summary>
 public void RenderText(TextRenderInfo renderInfo)
 {
     output.WriteLine("    <");
     Vector start = renderInfo.GetBaseline().GetStartPoint();
     output.WriteLine(String.Format("        x: {0} y: {1} length: {2} \n        Text: {3}",
         start[Vector.I1], start[Vector.I2],
         renderInfo.GetBaseline().GetLength(),
         renderInfo.GetText()));
     output.WriteLine("    >");
 }
예제 #16
0
 /// <summary>
 /// Stores the start and end points and the ascent and descent info from
 /// a text snippet into a Rectangle object.
 /// </summary>
 /// <param name="textRenderInfo">Object that contains info about a text snippet</param>
 /// <returns>coordinates in the form of a Rectangle object</returns>
 static Rectangle GetRectangle(TextRenderInfo textRenderInfo)
 {
     LineSegment descentLine = textRenderInfo.GetDescentLine();
     LineSegment ascentLine = textRenderInfo.GetAscentLine();
     float x0 = descentLine.GetStartPoint()[0];
     float x1 = descentLine.GetEndPoint()[0];
     float y0 = descentLine.GetStartPoint()[1];
     float y1 = ascentLine.GetEndPoint()[1];
     return new Rectangle(x0, y0, x1, y1);
 }
예제 #17
0
 /**
  * Applies filters, then delegates to the deleg if all filters pass
  * @param renderInfo contains info to render text
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
  */
 virtual public void RenderText(TextRenderInfo renderInfo)
 {
     foreach (RenderFilter filter in filters)
     {
         if (!filter.AllowText(renderInfo))
         {
             return;
         }
     }
     deleg.RenderText(renderInfo);
 }
        public void RenderText(TextRenderInfo renderInfo)
        {
            bool hardReturn = false;

            LineSegment segment = renderInfo.GetBaseline();
            Vector start = segment.GetStartPoint();
            Vector end = segment.GetEndPoint();

            if (lastStart != null && lastEnd != null)
            {
                Vector x0 = start;
                Vector x1 = lastStart;
                Vector x2 = lastEnd;

                // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
                float dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared;

                float sameLineThreshold = 1f; // we should probably base this on the current font metrics, but 1 pt seems to be sufficient for the time being
                if (dist > sameLineThreshold)
                    hardReturn = true;

                // Note:  Technically, we should check both the start and end positions, in case the angle of the text changed without any displacement
                // but this sort of thing probably doesn't happen much in reality, so we'll leave it alone for now
            }

            if (hardReturn)
            {
                //System.out.Println("<< Hard Return >>");
                result.Append('\n');
            }
            else if (lastStart != null && lastEnd != null)
            {
                if (result[result.Length - 1] != ' ' && renderInfo.GetText()[0] != ' ')
                { // we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
                    float spacing = lastEnd.Subtract(start).Length;
                    if (spacing > renderInfo.GetSingleSpaceWidth() / 2f)
                    {
                        result.Append('\t');
                        //System.out.Println("Inserting implied space before '" + renderInfo.GetText() + "'");
                    }
                }
            }
            else
            {
                //System.out.Println("Displaying first string of content '" + text + "' :: x1 = " + x1);
            }

            //System.out.Println("[" + renderInfo.GetStartPoint() + "]->[" + renderInfo.GetEndPoint() + "] " + renderInfo.GetText());
            result.Append(renderInfo.GetText());

            lastStart = start;
            lastEnd = end;
        }
예제 #19
0
        /**
         *
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment = renderInfo.GetBaseline();

            if (renderInfo.GetRise() != 0)
            { // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to
                Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
                segment = segment.TransformBy(riseOffsetTransform);
            }
            TextChunk tc = new TextChunk(renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment));

            locationalResult.Add(tc);
        }
예제 #20
0
        /// <summary>
        /// Creates a TextItem based on a TextRenderInfo object.
        /// </summary>
        /// <param name="textRenderInfo">the TextRenderInfo object</param>
        /// <param name="top">the Y coordinate of the top margin</param>
        public TextItem(TextRenderInfo textRenderInfo, float top)
        {
            textStyles.Add(new TextStyle("FranklinGothic", 10.5f), BaseColor.ORANGE);
            textStyles.Add(new TextStyle("FranklinGothic", 8f), BaseColor.GREEN);
            textStyles.Add(new TextStyle("NewBaskerville", 10f), BaseColor.BLUE);
            textStyles.Add(new TextStyle("Courier", 9.5f), BaseColor.BLUE);
            textStyles.Add(new TextStyle("CombiNumerals", 13.5f), BaseColor.PINK);
        

            baseline = textRenderInfo.GetBaseline().GetStartPoint()[1];
            rectangle = GetRectangle(textRenderInfo);
            color = GetColor(textRenderInfo, top);
        }
예제 #21
0
        /**
         *
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment = renderInfo.GetBaseline();

            if (renderInfo.GetRise() != 0)
            { // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to
                Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
                segment = segment.TransformBy(riseOffsetTransform);
            }
            TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth());

            locationalResult.Add(location);
        }
예제 #22
0
        /**
         * Method invokes by the PdfContentStreamProcessor.
         * Passes a TextRenderInfo for every text chunk that is encountered.
         * We'll use this object to obtain coordinates.
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        virtual public void RenderText(TextRenderInfo renderInfo)
        {
            if (textRectangle == null)
            {
                textRectangle = renderInfo.GetDescentLine().GetBoundingRectange();
            }
            else
            {
                textRectangle.Add(renderInfo.GetDescentLine().GetBoundingRectange());
            }

            textRectangle.Add(renderInfo.GetAscentLine().GetBoundingRectange());
        }
예제 #23
0
        /**
         * @see com.itextpdf.text.pdf.parser.RenderFilter#allowText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        public override bool AllowText(TextRenderInfo renderInfo)
        {
            LineSegment segment    = renderInfo.GetBaseline();
            Vector      startPoint = segment.GetStartPoint();
            Vector      endPoint   = segment.GetEndPoint();

            float x1 = startPoint[Vector.I1];
            float y1 = startPoint[Vector.I2];
            float x2 = endPoint[Vector.I1];
            float y2 = endPoint[Vector.I2];

            return(filterRect.IntersectsLine(x1, y1, x2, y2));
        }
예제 #24
0
            public void RenderText(TextRenderInfo renderInfo)
            {
                List<TextRenderInfo> subs = renderInfo.GetCharacterRenderInfos();
                TextRenderInfo previousCharInfo = subs[0];

                for (int i = 1; i < subs.Count; i++)
                {
                    TextRenderInfo charInfo = subs[i];
                    Vector previousEndPoint = previousCharInfo.GetBaseline().GetEndPoint();
                    Vector currentStartPoint = charInfo.GetBaseline().GetStartPoint();
                    AssertVectorsEqual(previousEndPoint, currentStartPoint, charInfo.GetText());
                    previousCharInfo = charInfo;
                }

            }
예제 #25
0
        public void RenderText(TextRenderInfo renderInfo)
        {
            bool firstRender = results.Count == 0;

            LineSegment segment = renderInfo.GetBaseline();
            Vector start = segment.GetStartPoint();
            Vector end = segment.GetEndPoint();

            int currentLineKey = (int)start[1];

            if (!firstRender)
            {
                Vector x0 = start;
                Vector x1 = lastStart;
                Vector x2 = lastEnd;

                float dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared;

                float sameLineThreshold = 1f;
                if (dist <= sameLineThreshold)
                {
                    currentLineKey = (int)lastStart[1];
                }
            }

            currentLineKey = currentLineKey * -1;
            if (!results.ContainsKey(currentLineKey))
            {
                results.Add(currentLineKey, new StringBuilder());
            }

            if (!firstRender &&
                results[currentLineKey].Length != 0 &&
                !results[currentLineKey].ToString().EndsWith(" ") &&
                renderInfo.GetText().Length > 0 &&
                !renderInfo.GetText().StartsWith(" "))
            {
                float spacing = lastEnd.Subtract(start).Length;
                if (spacing > renderInfo.GetSingleSpaceWidth() / 2f)
                {
                    results[currentLineKey].Append(" ");
                }
            }

            results[currentLineKey].Append(renderInfo.GetText());
            lastStart = start;
            lastEnd = end;
        }
        public override bool AllowText(TextRenderInfo renderInfo) {
            LineSegment ascent = renderInfo.GetAscentLine();
            LineSegment descent = renderInfo.GetDescentLine();

            Rectangle r1 = new Rectangle(Math.Min(descent.GetStartPoint()[0], descent.GetEndPoint()[0]),
                                         descent.GetStartPoint()[1],
                                         Math.Max(descent.GetStartPoint()[0], descent.GetEndPoint()[0]),
                                         ascent.GetEndPoint()[1]);

            foreach (Rectangle rectangle in rectangles) {
                if (Intersect(r1, rectangle)) {
                    return false;
                }
            }

            return true;
        }
예제 #27
0
 virtual public void RenderText(TextRenderInfo renderInfo)
 {
     for (int i = 0; i < delegates.Count; i++)
     {
         bool filtersPassed = true;
         foreach (RenderFilter filter in filters[i])
         {
             if (!filter.AllowText(renderInfo))
             {
                 filtersPassed = false;
                 break;
             }
         }
         if (filtersPassed)
         {
             delegates[i].RenderText(renderInfo);
         }
     }
 }
        //Automatically called for each chunk of text in the PDF
        public override void RenderText(TextRenderInfo renderInfo)
        {
            base.RenderText(renderInfo);

            //See if the current chunk contains the text
            var startPosition = System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf(
                renderInfo.GetText(), this.TextToSearchFor, this.CompareOptions);

            //If not found bail
            if (startPosition < 0)
            {
                return;
            }

            if (renderInfo.PdfString.ToString() != this.TextToSearchFor)
            {
                return;
            }

            //Grab the individual characters
            var chars =
                renderInfo.GetCharacterRenderInfos().Skip(startPosition).Take(this.TextToSearchFor.Length).ToList();

            //Grab the first and last character
            var firstChar = chars.First();
            var lastChar = chars.Last();

            //Get the bounding box for the chunk of text
            var bottomLeft = firstChar.GetDescentLine().GetStartPoint();
            var topRight = lastChar.GetAscentLine().GetEndPoint();

            //Create a rectangle from it
            var rect = new iTextSharp.text.Rectangle(
                bottomLeft[Vector.I1],
                bottomLeft[Vector.I2],
                topRight[Vector.I1],
                topRight[Vector.I2]
                );

            //Add this to our main collection
            this.MyPoints.Add(new RectAndText(rect, this.TextToSearchFor));
        }
            public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
            {
                string curFont = renderInfo.GetFont().PostscriptFontName;

                //Check if faux bold is used
                if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText))
                {
                    curFont += "-Bold";
                }

                //This code assumes that if the baseline changes then we're on a newline
                Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
                Vector topRight    = renderInfo.GetAscentLine().GetEndPoint();

                iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
                Single curFontSize             = rect.Height;

                //See if something has changed, either the baseline, the font or the font size
                if ((this.lastBaseLine == null) || (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) || (curFontSize != lastFontSize) || (curFont != lastFont))
                {
                    //if we've put down at least one span tag close it
                    if ((this.lastBaseLine != null))
                    {
                        this.result.AppendLine("</span>");
                    }
                    //If the baseline has changed then insert a line break
                    if ((this.lastBaseLine != null) && curBaseline[Vector.I2] != lastBaseLine[Vector.I2])
                    {
                        this.result.AppendLine("<br />");
                    }
                    //Create an HTML tag with appropriate styles
                    this.result.AppendFormat("<span style=\"font-family:{0};font-size:{1}\">", curFont, curFontSize);
                }

                //Append the current text
                this.result.Append(renderInfo.GetText());

                //Set currently used properties
                this.lastBaseLine = curBaseline;
                this.lastFontSize = curFontSize;
                this.lastFont     = curFont;
            }
        public override void RenderText(TextRenderInfo renderInfo)
        {
            base.RenderText(renderInfo);

            var bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
            var topRight = renderInfo.GetAscentLine().GetEndPoint();

            var rect = new iTextSharp.text.Rectangle(
                bottomLeft[Vector.I1],
                bottomLeft[Vector.I2],
                topRight[Vector.I1],
                topRight[Vector.I2]
            );

            this.containers.Add(new TextContainer()
            {
                Container = rect,
                Text = renderInfo.GetText()
            });
        }
예제 #31
0
        /**
         * Provides detail useful if a listener needs access to the position of each individual glyph in the text render operation
         * @return  A list of {@link TextRenderInfo} objects that represent each glyph used in the draw operation. The next effect is if there was a separate Tj opertion for each character in the rendered string
         * @since   5.3.3
         */
        public virtual IList <TextRenderInfo> GetCharacterRenderInfos()
        {
            IList <TextRenderInfo> rslt = new List <TextRenderInfo>(@string.Length);

            PdfString[] strings    = SplitString(@string);
            float       totalWidth = 0;

            for (int i = 0; i < strings.Length; i++)
            {
                float[]        widthAndWordSpacing = GetWidthAndWordSpacing(strings[i], true);
                TextRenderInfo subInfo             = new TextRenderInfo(this, strings[i], totalWidth);
                rslt.Add(subInfo);
                totalWidth += (widthAndWordSpacing[0] * gs.fontSize + gs.characterSpacing + widthAndWordSpacing[1]) *
                              gs.horizontalScaling;
            }
            foreach (TextRenderInfo tri in rslt)
            {
                tri.GetUnscaledWidth();
            }
            return(rslt);
        }
예제 #32
0
        public override bool AllowText(TextRenderInfo renderInfo) {
            LineSegment ascent = renderInfo.GetAscentLine();
            LineSegment descent = renderInfo.GetDescentLine();

        Point2D[] glyphRect = new Point2D[] {
                new Point2D.Float(ascent.GetStartPoint()[0], ascent.GetStartPoint()[1]),
                new Point2D.Float(ascent.GetEndPoint()[0], ascent.GetEndPoint()[1]),
                new Point2D.Float(descent.GetEndPoint()[0], descent.GetEndPoint()[1]),
                new Point2D.Float(descent.GetStartPoint()[0], descent.GetStartPoint()[1]),
        };

            foreach (Rectangle rectangle in rectangles) {
                Point2D[] redactRect = GetVertices(rectangle);

                if (Intersect(glyphRect, redactRect)) {
                    return false;
                }
            }

            return true;
        }
예제 #33
0
        public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {
            string curFont = renderInfo.GetFont().PostscriptFontName;

            if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText))
            {
                curFont += "-Bold";
            }

            Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
            Vector topRight    = renderInfo.GetAscentLine().GetEndPoint();

            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
            Single curFontSize             = rect.Height;

            if ((this.lastBaseLine == null) || (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) || (curFontSize != lastFontSize) || (curFont != lastFont))
            {
                if ((this.lastBaseLine != null))
                {
                    this.result.AppendLine("\"},");
                }
                if ((this.lastBaseLine != null) && curBaseline[Vector.I2] != lastBaseLine[Vector.I2])
                {
                    this.result.Append("<br />");
                }
                if (this.result.Length == 0)
                {
                    this.result.Append("{\"fontName\":\"" + curFont + "\",\"fontSize\":\"" + curFontSize + "\",\"text\":\"");
                }
                else
                {
                    this.result.Append("{\"fontName\":\"" + curFont + "\",\"fontSize\":\"" + curFontSize + "\",\"text\":\"");
                }
            }

            this.result.Append(renderInfo.GetText());
            this.lastBaseLine = curBaseline;
            this.lastFontSize = curFontSize;
            this.lastFont     = curFont;
        }
예제 #34
0
        /**
         * Provides detail useful if a listener needs access to the position of each individual glyph in the text render operation
         * @return A list of {@link TextRenderInfo} objects that represent each glyph used in the draw operation. The next effect is if there was a separate Tj opertion for each character in the rendered string
         * @since 5.3.3
         */
        public List <TextRenderInfo> GetCharacterRenderInfos()
        {
            List <TextRenderInfo> rslt = new List <TextRenderInfo>(text.Length);

            DocumentFont font = gs.font;

            char[] chars      = text.ToCharArray();
            float  totalWidth = 0;

            for (int i = 0; i < chars.Length; i++)
            {
                float w           = font.GetWidth(chars[i]) / 1000.0f;
                float wordSpacing = chars[i] == 32 ? gs.wordSpacing : 0f;

                TextRenderInfo subInfo = new TextRenderInfo(this, i, totalWidth);
                rslt.Add(subInfo);

                totalWidth += (w * gs.fontSize + gs.characterSpacing + wordSpacing) * gs.horizontalScaling;
            }

            return(rslt);
        }
        public virtual void RenderText(TextRenderInfo renderInfo) {
            if (renderInfo.PdfString.ToUnicodeString().Length == 0) {
                return;
            }

            // if true, than clipping path was completely cleaned
            if (newClippingPath.IsEmpty()) {
                LineSegment baseline = renderInfo.GetUnscaledBaseline();
                chunks.Add(new PdfCleanUpContentChunk.Text(renderInfo.PdfString, baseline.GetStartPoint(), 
                    baseline.GetEndPoint(), false, strNumber));
            } else {
                foreach (TextRenderInfo ri in renderInfo.GetCharacterRenderInfos()) {
                    bool isAllowed = filter.AllowText(ri);
                    LineSegment baseline = ri.GetUnscaledBaseline();

                    chunks.Add(new PdfCleanUpContentChunk.Text(ri.PdfString, baseline.GetStartPoint(),
                        baseline.GetEndPoint(), isAllowed, strNumber));
                }
            }

            ++strNumber;
        }
        public void RenderText(TextRenderInfo renderInfo)
        {
            var curFont = renderInfo.GetFont().PostscriptFontName;

              //Check if faux bold is used
              if ((renderInfo.GetTextRenderMode() == (int) TextRenderMode.FillThenStrokeText))
            curFont += "-Bold";

              //This code assumes that if the baseline changes then we're on a newline
              var curBaseline = renderInfo.GetBaseline().GetStartPoint();
              var topRight = renderInfo.GetAscentLine().GetEndPoint();
              var rect = new Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
              var curFontSize = rect.Height;

              //See if something has changed, either the baseline, the font or the font size
              if ((lastBaseLine == null) || (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) || (curFontSize != lastFontSize) ||
              (curFont != lastFont))
              {
            //if we've put down at least one span tag close it
            if ((lastBaseLine != null))
              result.AppendLine("</span>");

            //If the baseline has changed then insert a line break
            if ((lastBaseLine != null) && curBaseline[Vector.I2] != lastBaseLine[Vector.I2])
              result.AppendLine("<br />");

            //Create an HTML tag with appropriate styles
            result.AppendFormat("<span style=\"font-family:{0};font-size:{1}; position: relative; top: {2}; left: {3};\">",
              curFont, curFontSize, 850 - rect.Top, rect.Left);
              }

              //Append the current text
              result.Append(renderInfo.GetText());

              //Set currently used properties
              lastBaseLine = curBaseline;
              lastFontSize = curFontSize;
              lastFont = curFont;
        }
예제 #37
0
 /**
  * @param renderInfo
  * @return true if the text render operation should be performed
  */
 public virtual bool AllowText(TextRenderInfo renderInfo){
     return true;
 }
예제 #38
0
            public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
            {
                string curFont  = renderInfo.GetFont().PostscriptFontName;
                string curColor = "";

                try
                {
                    curColor = renderInfo.GetFillColor().ToString();
                }
                catch (Exception) { }
                curColor = curColor.Replace("Color value[", "").Replace("]", "");
                //Console.WriteLine(curColor);
                //string curColor = renderInfo.GetStrokeColor().RGB.ToString();
                //Check if faux bold is used
                if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText))
                {
                    curFont += "-Bold";
                }

                //This code assumes that if the baseline changes then we're on a newline
                Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
                Vector topRight    = renderInfo.GetAscentLine().GetEndPoint();


                iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
                Single curFontSize             = rect.Height;

                if (_doFootnoteCheck == true)
                {
                    string text = renderInfo.GetText();

                    //cislo < 3.92M && cislo > 3.8M
                    //cislo == 3.9104M || cislo == 3.910416M
                    if (Decimal.TryParse(curFontSize.ToString(), out currentFontSize) && (currentFontSize == 3.890762M))
                    {
                        string s = " ";
                        if (text == "1," || text == "2," || text == "3," || text == "4," || text == "5," || text == "6," || text == "7," ||
                            text == "1" || text == "2" || text == "3" || text == "4" || text == "5" || text == "6" || text == "7")
                        {
                            //Console.WriteLine(text);

                            if (_prevDoubleText.Length > 1)
                            {
                                s = _prevDoubleText.Substring(0, 1);
                            }
                            if (_prevDoubleText.Length == 2 && s == text && topRight[1] == _prevTopRight)
                            {
                                _badFootnoteFound = true;
                            }
                            _prevDoubleText = text;
                            _prevTopRight   = topRight[1];
                        }
                    }

                    //if (Decimal.TryParse(curFontSize.ToString(), out cislo) && (cislo > 3.5M || cislo < 4M) && !string.IsNullOrWhiteSpace(text) && Int32.TryParse(text, out icislo))
                    if (Decimal.TryParse(curFontSize.ToString(), out currentFontSize) && (currentFontSize == 3.9104M || currentFontSize == 3.910416M || currentFontSize == 3.910412M || currentFontSize == 3.890762M) && !string.IsNullOrWhiteSpace(text) && Int32.TryParse(text, out currentFootnoteValue))
                    {
                        if (topRight[1] > 0 && topRight[1] < 700)
                        {
                            //Console.WriteLine(pageCounter);

                            /*
                             * Console.WriteLine("------------------------------------------");
                             * Console.WriteLine(curFontSize);
                             * Console.WriteLine("page:" + pageCounter);
                             * Console.WriteLine("txt: " + text);
                             * Console.WriteLine("prv: " + prev_icislo);
                             * Console.WriteLine("trgh: " + topRight[1]);
                             * Console.WriteLine("------------------------------------------");
                             */
                            if (!dictionary.ContainsKey(currentFootnoteValue))
                            {
                                dictionary.Add(currentFootnoteValue, (float)topRight[1]);

                                dr             = dt.NewRow();
                                dr["Number"]   = currentFootnoteValue;
                                dr["Position"] = (float)topRight[1];
                                dr["Page"]     = (int)pageCounter;
                                dt.Rows.Add(dr);
                            }
                            else
                            {
                                if (replaceCounter < 10)
                                {
                                    dictionary[currentFootnoteValue] = (float)topRight[1];
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        if (dt.Rows[i][0].ToString() == currentFootnoteValue.ToString().Trim())
                                        {
                                            dt.Rows[i][1] = (float)topRight[1];
                                            dt.Rows[i][2] = pageCounter;
                                        }
                                    }
                                    dr             = dt.NewRow();
                                    dr["Number"]   = currentFootnoteValue;
                                    dr["Position"] = (float)topRight[1];
                                    dr["Page"]     = (int)pageCounter;
                                    dt.Rows.Add(dr);
                                    replaceCounter++;
                                }
                            }
                        }
                        _prevInumber = currentFootnoteValue;
                    }
                }
                if (curColor == "FFFF0000")
                {
                    //Console.WriteLine("Red detected!");
                    //Console.WriteLine(curColor);
                    string s = renderInfo.GetText();
                    if (string.IsNullOrWhiteSpace(s))
                    {
                    }
                    else
                    {
                        //Console.WriteLine(s);
                        redWords.Add(s);
                        _redWords++;
                    }
                }
                //See if something has changed, either the baseline, the font or the font size
                if ((this.lastBaseLine == null) || (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) || (curFontSize != lastFontSize) || (curFont != lastFont))
                {
                    //if we've put down at least one span tag close it
                    if ((this.lastBaseLine != null))
                    {
                        this.result.AppendLine("</span>");
                    }
                    //If the baseline has changed then insert a line break
                    if ((this.lastBaseLine != null) && curBaseline[Vector.I2] != lastBaseLine[Vector.I2])
                    {
                        this.result.AppendLine("<br />");
                    }
                    //Create an HTML tag with appropriate styles

                    this.result.AppendFormat("<span style=\"font-family:{0};font-size:{1}\font-color:{2}>", curFont, curFontSize, curColor);
                }

                //Append the current text
                this.result.Append(renderInfo.GetText());

                //Set currently used properties
                this.lastBaseLine = curBaseline;
                this.lastFontSize = curFontSize;
                this.lastFont     = curFont;
            }
예제 #39
0
 /// <see cref="IRenderListener.RenderText"/>
 public void RenderText(TextRenderInfo renderInfo)
 {
     items.Add(new TextItem(renderInfo, top));
 }
예제 #40
0
 /**
  * @param renderInfo
  * @return true if the text render operation should be performed
  */
 public virtual bool AllowText(TextRenderInfo renderInfo)
 {
     return(true);
 }
예제 #41
0
 public void RenderText(TextRenderInfo renderInfo) {
     buffer.Append(renderInfo.GetText());
     buffer.Append("\n");
 }
        //Automatically called for each chunk of text in the PDF
        public override void RenderText(TextRenderInfo renderInfo) {
            base.RenderText(renderInfo);

            //Get the bounding box for the chunk of text
            var bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
            var topRight = renderInfo.GetAscentLine().GetEndPoint();

            //Create a rectangle from it
            var rect = new iTextSharp.text.Rectangle(
                                                    bottomLeft[Vector.I1],
                                                    bottomLeft[Vector.I2],
                                                    topRight[Vector.I1],
                                                    topRight[Vector.I2]
                                                    );

            //Add this to our main collection
            this.myPoints.Add(new RectAndText(rect, renderInfo.GetText()));
        }
예제 #43
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="renderInfo"></param>
 public override void RenderText(TextRenderInfo renderInfo)
 {
     iTextSharp.text.pdf.parser.LineSegment segment = renderInfo.GetBaseline();
     TextChunkEx location = new TextChunkEx(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine());
     m_locationResult.Add(location);
 }
예제 #44
0
 public ITextChunkLocation CreateLocation(TextRenderInfo renderInfo, LineSegment baseline)
 {
     return(new TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth()));
 }
예제 #45
0
 public override void RenderText(TextRenderInfo renderInfo) {
     foreach (TextRenderInfo tri in renderInfo.GetCharacterRenderInfos())
         base.RenderText(tri);
 }
 virtual public void RenderText(TextRenderInfo renderInfo) {
     textChunks.Add(renderInfo.GetText());
 }
예제 #47
0
 public virtual void RenderText(TextRenderInfo renderInfo) {
     Vector startPoint = renderInfo.GetDescentLine().GetStartPoint();
     Vector endPoint = renderInfo.GetAscentLine().GetEndPoint();
     float x1 = Math.Min(startPoint[0], endPoint[0]);
     float x2 = Math.Max(startPoint[0], endPoint[0]);
     float y1 = Math.Min(startPoint[1], endPoint[1]);
     float y2 = Math.Max(startPoint[1], endPoint[1]);
     rectangles.Add(new Rectangle(x1, y1, x2, y2));
 }
 // ---------------------------------------------------------------------------
 /**
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(
  *     com.itextpdf.text.pdf.parser.TextRenderInfo)
  */
 public void RenderText(TextRenderInfo renderInfo)
 {
 }
        public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {//.Remove(0,7)
            string curFont = renderInfo.GetFont().PostscriptFontName;
            string Bold    = "NOTBOLD";
            string Color;
            float  URX = 0f;
            float  URY = 0f;
            float  LLX = 0f;
            float  LLY = 0f;

            //Check if faux bold is used
            if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText))
            {
                Bold = "BOLD";
            }
            Color = "Not Available;";
            try
            {
                Color = renderInfo.GetFillColor().ToString();
            }
            catch (Exception)
            {
            }
            //This code assumes that if the baseline changes then we're on a newline
            Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
            Vector topRight    = renderInfo.GetAscentLine().GetEndPoint();

            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
            Single curFontSize             = rect.Height;

            //See if something has changed, either the baseline, the font or the font size
            if ((this.lastBaseLine == null) || (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) || (curFontSize != lastFontSize) || (curFont != lastFont))
            {
                URX = topRight[Vector.I1];
                URY = topRight[Vector.I2];
                LLX = curBaseline[Vector.I1];
                LLY = curBaseline[Vector.I2];

                //if we've put down at least one span tag close it
                if ((this.lastBaseLine != null))
                {
                    this.result.AppendLine("</span>");
                }
                //If the baseline has changed then insert a line break
                if ((this.lastBaseLine != null) && curBaseline[Vector.I2] != lastBaseLine[Vector.I2])
                {
                    this.result.AppendLine("<br />");
                }

                //Create an HTML tag with appropriate styles
                this.result.AppendFormat("<span style=\"font-family:{0};font-size:{1};z={2};color={3};coordinates:{4},{5},{6},{7};\">", curFont, curFontSize, Bold, Color, URX, URY, LLX, LLY);
            }

            //Append the current text
            this.result.Append(renderInfo.GetText());

            //Set currently used properties
            this.lastBaseLine = curBaseline;
            this.lastFontSize = curFontSize;
            this.lastFont     = curFont;
        }
예제 #50
0
 /// <summary>
 /// Creates a TextItem based on a TextRenderInfo object.
 /// </summary>
 /// <param name="textRenderInfo">the TextRenderInfo object</param>
 public TextItemSimple(TextRenderInfo textRenderInfo)
 {
     baseline = textRenderInfo.GetBaseline().GetStartPoint()[1];
     rectangle = GetRectangle(textRenderInfo);
     color = BaseColor.BLUE;
 }
예제 #51
0
 /**
  * @see com.itextpdf.text.pdf.parser.RenderFilter#allowText(com.itextpdf.text.pdf.parser.TextRenderInfo)
  */
 public override bool AllowText(TextRenderInfo renderInfo)
 {
     return(renderInfo.HasMcid(mcid));
 }
예제 #52
0
 public override bool AllowText(TextRenderInfo renderInfo) {
     return renderInfo.HasMcid(mcid, true);
 }
예제 #53
0
        /**
         * Displays text.
         * @param string    the text to display
         */
        private void DisplayPdfString(PdfString str){

            String unicode = Decode(str);

            TextRenderInfo renderInfo = new TextRenderInfo(unicode, Gs(), textMatrix, markedContentStack);

            renderListener.RenderText(renderInfo);

            textMatrix = new Matrix(renderInfo.GetUnscaledWidth(), 0).Multiply(textMatrix);
        }