/// <summary> /// Obtiene el texto contenido en un pdf en función del parámetro facilitado. /// </summary> /// <param name="renderInfo">Información para la obtención del texto.</param> public override void RenderText(TextRenderInfo renderInfo) { base.RenderText(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); } var ll = renderInfo.GetDescentLine().GetStartPoint(); // lower left var ur = renderInfo.GetAscentLine().GetEndPoint(); // upper right string text = renderInfo.GetText(); //mirando string fillColor = renderInfo.GetFillColor()?.ToString(); // Color del texto. string strokeColor = renderInfo.GetStrokeColor()?.ToString(); // Color del texto. 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]); double fontSize = Math.Round(rect.Height); // Tamaño de la fuente a partir del rectángulo extraído. string fontName = renderInfo.GetFont()?.PostscriptFontName; //Nombre de la fuente. //base._PdfTextChunks.Add(new PdfTextChunk(renderInfo.GetText(), base.tclStrat.CreateLocation(renderInfo, segment), ll, ur)); _PdfColorFontTextChunks.Add(new PdfColorFontTextChunk(renderInfo.GetText(), base.tclStrat.CreateLocation(renderInfo, segment), ll, ur, fillColor, strokeColor, fontName, fontSize)); }
public virtual void RenderText(TextRenderInfo renderInfo) { LineSegment segment = renderInfo.GetBaseline(); TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth()); var _with1 = location; //Chunk Location: Debug.Print(renderInfo.GetText()); _with1.PosLeft = renderInfo.GetDescentLine().GetStartPoint()[Vector.I2]; _with1.PosRight = renderInfo.GetAscentLine().GetEndPoint()[Vector.I2]; _with1.PosBottom = renderInfo.GetDescentLine().GetStartPoint()[Vector.I2]; _with1.PosTop = renderInfo.GetAscentLine().GetEndPoint()[Vector.I2]; //Chunk Font Size: (Height) _with1.curFontSize = _with1.PosTop - segment.GetStartPoint()[Vector.I2]; //Use Font name and Size as Key in the SortedList string StrKey = renderInfo.GetFont().PostscriptFontName + _with1.curFontSize.ToString(); //Add this font to ThisPdfDocFonts SortedList if it's not already present if (!ThisPdfDocFonts.ContainsKey(StrKey)) { ThisPdfDocFonts.Add(StrKey, renderInfo.GetFont()); } //Store the SortedList index in this Chunk, so we can get it later _with1.FontIndex = ThisPdfDocFonts.IndexOfKey(StrKey); locationalResult.Add(location); }
//-------------------------------------------------------------------------------------------------- public void RenderText(TextRenderInfo renderInfo) { LineSegment segment = renderInfo.GetBaseline(); TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth()); location.iPage = Page; int renderInfoTextLength = new StringInfo(renderInfo.GetText()).LengthInTextElements; if (renderInfoTextLength == 1) { location.AscentLines.Add(renderInfo.GetAscentLine()); location.DescentLines.Add(renderInfo.GetDescentLine()); } else { IList <TextRenderInfo> infos = renderInfo.GetCharacterRenderInfos(); System.Diagnostics.Debug.Assert(infos != null); System.Diagnostics.Debug.Assert(renderInfoTextLength == infos.Count); foreach (TextRenderInfo info in infos) { location.AscentLines.Add(info.GetAscentLine()); location.DescentLines.Add(info.GetDescentLine()); } } m_LocationalResult.Add(location); }
public virtual void RenderText(TextRenderInfo renderInfo) { bool firstRender = results.Count == 0; LineSegment segment = renderInfo.GetBaseline(); Vector start = segment.GetStartPoint(); Vector end = segment.GetEndPoint(); //Use the Y value of the bottom left corner of the text for the key 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 we've detected that we're still on the same if (dist <= sameLineThreshold) { //Use the previous Y coordinate currentLineKey = (int)lastStart[1]; } } //Hack: PDFs start with zero at the bottom so our keys will be upside down. Using negative keys cheats this. currentLineKey = currentLineKey * -1; //If this line hasn't been used before add a new line to our collection if (!results.ContainsKey(currentLineKey)) { results.Add(currentLineKey, new StringBuilder()); } //Insert a space between blocks of text if it appears there should be if (!firstRender && //First pass never needs a leading space results[currentLineKey].Length != 0 && //Don't append a space to the begining of a line !results[currentLineKey].ToString().EndsWith(" ") && //Don't append if the current buffer ends in a space already renderInfo.GetText().Length > 0 && //Don't append if the new next is empty !renderInfo.GetText().StartsWith(" ")) { //Don't append if the new text starts with a space //Calculate the distance between the two blocks float spacing = lastEnd.Subtract(start).Length; //If it "looks" like it should be a space if (spacing > renderInfo.GetSingleSpaceWidth() / 2f) { //Add a space results[currentLineKey].Append(" "); } } //Add the text to the line in our collection results[currentLineKey].Append(renderInfo.GetText()); lastStart = start; lastEnd = end; }
public void RenderText(TextRenderInfo renderInfo) { _builder.Append(renderInfo.GetText() + " "); // New page detected at copywrite statement. if (renderInfo.GetText().Equals("Reserved.")) { pages.Add(_builder.ToString()); _builder.Clear(); } }
public virtual void EventOccurred(IEventData data, EventType type) { if (type.Equals(EventType.RENDER_TEXT)) { TextRenderInfo renderInfo = (TextRenderInfo)data; bool firstRender = result.Length == 0; bool hardReturn = false; LineSegment segment = renderInfo.GetBaseline(); Vector start = segment.GetStartPoint(); Vector end = segment.GetEndPoint(); if (!firstRender) { Vector x1 = lastStart; Vector x2 = lastEnd; // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html float dist = (x2.Subtract(x1)).Cross((x1.Subtract(start))).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() + "'"); //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; } }
public virtual 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 distance = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared; float sameLineThreshold = 1f; if (distance <= 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; }
//This is called whenever a run of text is encountered public void RenderText(TextRenderInfo renderInfo) { //This code assumes that if the baseline changes then we're on a newline LineSegment curBaseline = renderInfo.GetBaseline(); Vector curBaseLineStart = curBaseline.GetStartPoint(); if (lastBaseLine != null) { // Check if text is on a new line or if text is new block of text on the same line // Horizontally compare max coordinate of previous block with min of current block // For vertical compare max of both to get the base of the textblock var horizontalDifference = Math.Abs(Math.Max(lastBaseLine.GetStartPoint()[0], lastBaseLine.GetEndPoint()[0]) - Math.Min(curBaseline.GetStartPoint()[0], curBaseline.GetEndPoint()[0])); var verticalDifference = Math.Abs(Math.Max(lastBaseLine.GetStartPoint()[1], lastBaseLine.GetEndPoint()[1]) - Math.Max(curBaseline.GetStartPoint()[1], curBaseline.GetEndPoint()[1])); if (verticalDifference > 1 || horizontalDifference > 20) //if ((this.lastBaseLine != null) && (curBaseline[Vector.I2] != lastBaseLine[Vector.I2])) { //See if we have text and not just whitespace if ((!String.IsNullOrWhiteSpace(result.ToString()))) { //Mark the previous line as done by adding it to our buffers this.baselines.Add(this.lastBaseLine.GetStartPoint()[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; }
//Automatically called for each chunk of text in the PDF public override void RenderText(TextRenderInfo wholeRenderInfo) { base.RenderText(wholeRenderInfo); GraphicsState gs = (GraphicsState)GsField.GetValue(wholeRenderInfo); myChunks.Add(new SizeAndTextAndFont(gs.FontSize, wholeRenderInfo.GetText(), wholeRenderInfo.GetFont().PostscriptFontName)); }
public virtual void ParseText(TextRenderInfo textRenderInfo) { var text = textRenderInfo.GetText(); LineSegment baseline = textRenderInfo.GetBaseline(); if (textRenderInfo.GetRise() != 0) { Matrix m = new Matrix(0.0f, -textRenderInfo.GetRise()); baseline = baseline.TransformBy(m); } var start = baseline.GetStartPoint(); LineSegment ascentLine = textRenderInfo.GetAscentLine(); PdfTextBlock item = new PdfTextBlock { Value = text, Bottom = pageContext.PageHeight - start.Get(Vector.I2), Top = pageContext.PageHeight - ascentLine.GetStartPoint().Get(Vector.I2), Left = start.Get(Vector.I1), Width = baseline.GetEndPoint().Get(Vector.I1) - start.Get(Vector.I1), FontSize = FontManager.Instance.GetFontSize(textRenderInfo, baseline, ascentLine), StrokeColore = ColorManager.Instance.GetColor(textRenderInfo), CharSpacing = textRenderInfo.GetSingleSpaceWidth(), Font = GetFont(textRenderInfo), }; RightToLeftManager.Instance.AssignRtl(item, textRenderInfo.GetUnscaledWidth() < 0); pageContext.LinkManager.AssignLink(item); texts.Add(item); }
/** * * @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); //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] ); TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), rect); locationalResult.Add(location); }
/// <summary> /// /// </summary> /// <param name="renderInfo"></param> public override void RenderText(TextRenderInfo renderInfo) { LineSegment segment = renderInfo.GetBaseline(); MyTextChunk location = new MyTextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine()); m_locationResult.Add(location); }
public void RenderText(TextRenderInfo renderInfo) { obj.sb.AppendLine(renderInfo.GetText()); //LineSegment segment = renderInfo.GetBaseline(); //TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine()); //obj.GetResult().Add(location); }
/// <summary> /// Render text. /// </summary> /// <param name="renderInfo">render text information</param> public void RenderText(TextRenderInfo renderInfo) { var segment = renderInfo.GetBaseline(); var location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth()) { PosLeft = renderInfo.GetDescentLine().GetStartPoint()[Vector.I1], PosRight = renderInfo.GetAscentLine().GetEndPoint()[Vector.I1], PosBottom = renderInfo.GetDescentLine().GetStartPoint()[Vector.I2], PosTop = renderInfo.GetAscentLine().GetEndPoint()[Vector.I2], FillColor = renderInfo.GetFillColor(), StrokeColor = renderInfo.GetStrokeColor(), Font = renderInfo.GetFont() }; // Chunk Font Size: (Height) location.CurFontSize = location.PosTop - segment.GetStartPoint()[Vector.I2]; // Use Font name and Size as Key in the SortedList var strKey = renderInfo.GetFont().PostscriptFontName + location.CurFontSize; // Add this font to ThisPdfDocFonts SortedList if it's not already present if (!_thisPdfDocFonts.ContainsKey(strKey)) { _thisPdfDocFonts.Add(strKey, renderInfo.GetFont()); } // Store the SortedList index in this Chunk, so we can get it later location.FontIndex = _thisPdfDocFonts.IndexOfKey(strKey); _locationalResult.Add(location); }
public void RenderText(TextRenderInfo renderInfo) { var text = renderInfo.GetText(); _token.Append(text); _token.Append(" "); }
private TextChunkInfo(Vector startLocation, Vector endLocation, TextRenderInfo info) : base(info.GetText(), startLocation, endLocation, info.GetSingleSpaceWidth()) { RenderInfo = info; StartLocation = startLocation; EndLocation = endLocation; }
//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 Rectangle(bottomLeft[Vector.I1], bottomLeft[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]); if (!string.IsNullOrWhiteSpace(renderInfo.GetText())) { //Add this to our main collection myPoints.Add(new RectAndText(rect, renderInfo.GetText())); } }
public override void RenderText(TextRenderInfo renderInfo) { LineSegment baseline = renderInfo.GetBaseline(); //Create ExtendedChunk ExtendedTextChunk aExtendedChunk = new ExtendedTextChunk(renderInfo.GetText(), baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetCharacterRenderInfos().ToList()); this.m_DocChunks.Add(aExtendedChunk); }
public void RenderText(TextRenderInfo renderInfo) { if (expectingTitle) { expectingTitle = false; File.WriteAllText(string.Format(format, imageNumber, "txt"), renderInfo.GetText()); } }
/// 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() }); }
public void RenderText(TextRenderInfo renderInfo) { Chunks.Add(new Chunk { TopLeft = renderInfo.GetAscentLine().GetStartPoint(), BottomRight = renderInfo.GetDescentLine().GetEndPoint(), Text = renderInfo.GetText(), }); }
public void RenderText(TextRenderInfo renderInfo) { if (this.IsNewBoxStarting(renderInfo)) { BeginNewBox(); } this.m_CurrentCheckboxBox.Name += renderInfo.GetText() + " "; }
public override void RenderText(TextRenderInfo renderInfo) { base.RenderText(renderInfo); string text = renderInfo.GetText(); Vector bottomLeft = renderInfo.GetDescentLine().GetStartPoint(); Vector topRight = renderInfo.GetAscentLine().GetEndPoint(); Rectangle rectangle = new Rectangle(bottomLeft[Vector.I1], bottomLeft[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]); Chunks.Add(new TableTextChunk(rectangle, text)); }
public override void RenderText(TextRenderInfo renderInfo) { base.RenderText(renderInfo); var rectangle = GetRectangleFromReaderInfo(renderInfo); var text = renderInfo.GetText(); TextsWithLocations.Add(new TextWithLocation(rectangle, text, _currentPdfPosition)); _currentPdfPosition += text.Length; }
public CharacterRenderInfo(TextRenderInfo tri) : base(tri == null ? "" : tri.GetText(), tri == null ? null : GetLocation(tri)) { if (tri == null) { throw new ArgumentException("TextRenderInfo argument is not nullable."); } if (tri.GetText().Length != 1) { throw new ArgumentException("CharacterRenderInfo objects represent a single character. They should not be made from TextRenderInfo objects containing more than a single character of text." ); } // determine bounding box float x0 = tri.GetDescentLine().GetStartPoint().Get(0); float y0 = tri.GetDescentLine().GetStartPoint().Get(1); float h = tri.GetAscentLine().GetStartPoint().Get(1) - tri.GetDescentLine().GetStartPoint().Get(1); float w = Math.Abs(tri.GetBaseline().GetStartPoint().Get(0) - tri.GetBaseline().GetEndPoint().Get(0)); this.boundingBox = new Rectangle(x0, y0, w, h); }
public override void RenderText(TextRenderInfo renderInfo) { base.RenderText(renderInfo); //Vector bottomLeft = renderInfo.GetDescentLine().GetStartPoint(); Vector bottomLeft = renderInfo.GetBaseline().GetStartPoint(); Vector topRight = renderInfo.GetAscentLine().GetEndPoint(); TextChunk tc = new TextChunk(renderInfo.GetText(), bottomLeft, topRight, renderInfo.GetSingleSpaceWidth()); TextChunks.Add(tc); }
/// <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(" >"); }
public void RenderText(TextRenderInfo renderInfo) { var a = renderInfo.GetBaseline(); var ascentLine = renderInfo.GetAscentLine(); var a2 = renderInfo.GetSingleSpaceWidth(); var descentLine = renderInfo.GetDescentLine(); var a4 = renderInfo.GetUnscaledBaseline(); var a5 = renderInfo.GetFont(); var a6 = renderInfo.GetRise(); var a7 = renderInfo.GetText(); bool flag1 = this.result.Length == 0; bool flag2 = false; LineSegment baseline = renderInfo.GetBaseline(); Vector startPoint = baseline.GetStartPoint(); Vector endPoint = baseline.GetEndPoint(); if (!flag1) { Vector v = startPoint; Vector lastStart = this.lastStart; Vector lastEnd = this.lastEnd; if ((double)(lastEnd.Subtract(lastStart).Cross(lastStart.Subtract(v)).LengthSquared / lastEnd.Subtract(lastStart).LengthSquared) > 1.0) { flag2 = true; } } RectangleF rectCurrent = getRenderRectangleF(renderInfo); if (flag2) { this.AppendTextChunk('\n'); } //else if (!flag1 && this.result[this.result.Length - 1] != ' ' && (renderInfo.GetText().Length > 0 && renderInfo.GetText()[0] != ' ') && (double)this.lastEnd.Subtract(startPoint).Length > (double)renderInfo.GetSingleSpaceWidth() / 2.0) // this.AppendTextChunk(' '); this.AppendTextChunk(renderInfo.GetText()); this.lastStart = startPoint; this.lastEnd = endPoint; }
public void RenderText(TextRenderInfo renderInfo) { Text.Append(renderInfo.GetText()); LineSegment segment = renderInfo.GetBaseline(); Vector start = segment.GetStartPoint(); Text.Append(Constants.CharSeparator); Text.Append(start[Vector.I1]); Text.Append(Constants.PointSeparator); Text.Append(start[Vector.I2]); Text.Append(Constants.MainSeparator); }
public override 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); }