/// <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]; }
/** * 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()); }
/** * 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()); }
/// <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); }
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; }
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() }); }
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; }
//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())); }
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)); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="renderInfo"></param> public override void RenderText(TextRenderInfo renderInfo) { LineSegment segment = renderInfo.GetBaseline(); string x = renderInfo.GetText(); TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine()); m_locationResult.Add(location); }
//Automatically called for each chunk of text in the PDF public override void RenderText(TextRenderInfo renderInfo) { base.RenderText(renderInfo); var startPosition = System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf(renderInfo.GetText(), this.TextToSearchFor, this.CompareOptions); var texto = renderInfo.GetText(); var x = renderInfo.GetText().Contains(TextToSearchFor); //Get the bounding box for the chunk of text /*if (x) { 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] ); this.myPoints.Add(new RectAndText(rect, renderInfo.GetText())); }*/ //This code assumes that if the baseline changes then we're on a newline Vector curBaseline = renderInfo.GetBaseline().GetStartPoint(); Vector curBaseline2 = renderInfo.GetAscentLine().GetEndPoint(); //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()); if (this.result.ToString().ToLower().Contains(TextToSearchFor.ToLower())) { //Create a rectangle from it var rect = new iTextSharp.text.Rectangle(startPositionWord[Vector.I1], startPositionWord[Vector.I2], lastAscentLine[Vector.I1], lastAscentLine[Vector.I2]); this.myPoints.Add(new RectAndText(rect, this.result.ToString())); startPositionWord = null; endPositionWord = null; } } //Reset our "line" buffer this.result.Clear(); wordended = true; } //Append the current text to our line buffer //if (!string.IsNullOrWhiteSpace(renderInfo.GetText())) this.result.Append(renderInfo.GetText()); if (!string.IsNullOrWhiteSpace(result.ToString()) && wordended) { wordended = false; startPositionWord = renderInfo.GetDescentLine().GetStartPoint(); } //Reset the last used line this.lastBaseLine = curBaseline; this.lastAscentLine = curBaseline2; }