Exemplo n.º 1
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);

            //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>
        /// 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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        private static LineSegment GetSegment(TextRenderInfo info)
        {
            var segment = info.GetBaseline();

            if (Math.Abs(info.GetRise()) > 0.01)
            {
                segment.TransformBy(new Matrix(0, -info.GetRise()));
            }
            return(segment);
        }
        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);
        }
Exemplo n.º 6
0
    public override void RenderText(TextRenderInfo renderInfo)
    {
        textLineFinder.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);
        }
        TextChunk location = new HorizontalTextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), textLineFinder);

        getLocationalResult().Add(location);
    }
Exemplo n.º 7
0
        public virtual void EventOccurred(IEventData data, EventType type)
        {
            if (type.Equals(EventType.RENDER_TEXT))
            {
                TextRenderInfo renderInfo = (TextRenderInfo)data;
                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);
                }
                if (useActualText)
                {
                    CanvasTag lastTagWithActualText = lastTextRenderInfo != null?FindLastTagWithActualText(lastTextRenderInfo
                                                                                                           .GetCanvasTagHierarchy()) : null;

                    if (lastTagWithActualText != null && lastTagWithActualText == FindLastTagWithActualText(renderInfo.GetCanvasTagHierarchy
                                                                                                                ()))
                    {
                        // Merge two text pieces, assume they will be in the same line
                        LocationTextExtractionStrategy.TextChunk lastTextChunk = locationalResult[locationalResult.Count - 1];
                        Vector mergedStart = new Vector(Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(0), segment.GetStartPoint
                                                                     ().Get(0)), Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(1), segment.GetStartPoint().Get
                                                                                              (1)), Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(2), segment.GetStartPoint().Get(2)));
                        Vector mergedEnd = new Vector(Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(0), segment.GetEndPoint
                                                                   ().Get(0)), Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(1), segment.GetEndPoint().Get(1)
                                                                                        ), Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(2), segment.GetEndPoint().Get(2)));
                        LocationTextExtractionStrategy.TextChunk merged = new LocationTextExtractionStrategy.TextChunk(lastTextChunk
                                                                                                                       .GetText(), tclStrat.CreateLocation(renderInfo, new LineSegment(mergedStart, mergedEnd)));
                        locationalResult[locationalResult.Count - 1] = merged;
                    }
                    else
                    {
                        String actualText = renderInfo.GetActualText();
                        LocationTextExtractionStrategy.TextChunk tc = new LocationTextExtractionStrategy.TextChunk(actualText != null
                             ? actualText : renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment));
                        locationalResult.Add(tc);
                    }
                }
                else
                {
                    LocationTextExtractionStrategy.TextChunk tc = new LocationTextExtractionStrategy.TextChunk(renderInfo.GetText
                                                                                                                   (), tclStrat.CreateLocation(renderInfo, segment));
                    locationalResult.Add(tc);
                }
                lastTextRenderInfo = renderInfo;
            }
        }
Exemplo n.º 8
0
        /// <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);
            }

            string fontName      = renderInfo.GetFont().PostscriptFontName; // Nombre de la fuente del texto.
            string textoExtraido = renderInfo.GetText();                    // Grupo de texto sobre el que estamos iterando.

            var ll = renderInfo.GetDescentLine().GetStartPoint();           // lower left
            var ur = renderInfo.GetAscentLine().GetEndPoint();              // upper right

            _PdfTextChunks.Add(new PdfTextChunk(renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment), ll, ur));
        }
 public virtual void EventOccurred(IEventData data, EventType type)
 {
     if (type.Equals(EventType.RENDER_TEXT))
     {
         TextRenderInfo textRenderInfo = (TextRenderInfo)data;
         LineSegment    lineSegment    = textRenderInfo.GetBaseline();
         if (textRenderInfo.GetRise() != 0f)
         {
             Matrix m = new Matrix(0f, -textRenderInfo.GetRise());
             lineSegment = lineSegment.TransformBy(m);
         }
         if (this.useActualText)
         {
             CanvasTag canvasTag = (this.lastTextRenderInfo != null) ? this.FindLastTagWithActualText(this.lastTextRenderInfo.GetCanvasTagHierarchy()) : null;
             if (canvasTag != null && canvasTag == this.FindLastTagWithActualText(textRenderInfo.GetCanvasTagHierarchy()))
             {
                 LocationTextExtractionStrategy2.TextChunk textChunk = this.locationalResult[this.locationalResult.Count - 1];
                 Vector startPoint = new Vector(Math.Min(textChunk.GetLocation().GetStartLocation().Get(0), lineSegment.GetStartPoint().Get(0)), Math.Min(textChunk.GetLocation().GetStartLocation().Get(1), lineSegment.GetStartPoint().Get(1)), Math.Min(textChunk.GetLocation().GetStartLocation().Get(2), lineSegment.GetStartPoint().Get(2)));
                 Vector endPoint   = new Vector(Math.Max(textChunk.GetLocation().GetEndLocation().Get(0), lineSegment.GetEndPoint().Get(0)), Math.Max(textChunk.GetLocation().GetEndLocation().Get(1), lineSegment.GetEndPoint().Get(1)), Math.Max(textChunk.GetLocation().GetEndLocation().Get(2), lineSegment.GetEndPoint().Get(2)));
                 LocationTextExtractionStrategy2.TextChunk value = new LocationTextExtractionStrategy2.TextChunk(textChunk.GetText(), this.tclStrat.CreateLocation(textRenderInfo, new LineSegment(startPoint, endPoint)));
                 this.locationalResult[this.locationalResult.Count - 1] = value;
             }
             else
             {
                 string actualText = textRenderInfo.GetActualText();
                 LocationTextExtractionStrategy2.TextChunk item = new LocationTextExtractionStrategy2.TextChunk((actualText != null) ? actualText : textRenderInfo.GetText(), this.tclStrat.CreateLocation(textRenderInfo, lineSegment));
                 this.locationalResult.Add(item);
             }
         }
         else
         {
             LocationTextExtractionStrategy2.TextChunk item2 = new LocationTextExtractionStrategy2.TextChunk(textRenderInfo.GetText(), this.tclStrat.CreateLocation(textRenderInfo, lineSegment));
             this.locationalResult.Add(item2);
         }
         this.lastTextRenderInfo = textRenderInfo;
     }
 }
Exemplo n.º 10
0
            public void RenderText(TextRenderInfo renderInfo)
            {
                float rise = renderInfo.GetRise();

                if (rise != 0)
                {
                    throw new NotImplementedException();
                }
                if (!m_textRenderInfoSimple.TrySet(renderInfo))
                {
                    throw new NotImplementedException();
                }
                var         text             = renderInfo.GetText();
                float       descentY         = m_textRenderInfoSimple.OriginY - m_textRenderInfoSimple.Descent;
                float       ascentY          = m_textRenderInfoSimple.OriginY + m_textRenderInfoSimple.Ascent;
                int         lineBuilderIndex = GetLineBuilderIndex(descentY, ascentY);
                LineBuilder lineBuilder;

                if (lineBuilderIndex < 0)
                {
                    lineBuilderIndex = ~lineBuilderIndex;
                    if (0 < lineBuilderIndex && descentY <= m_lineBuilders[lineBuilderIndex - 1].MaxY)
                    {
                        throw new NotImplementedException();
                    }
                    if (lineBuilderIndex < m_lineBuilders.Count && m_lineBuilders[lineBuilderIndex].MinY <= ascentY)
                    {
                        throw new NotImplementedException();
                    }
                    lineBuilder      = new LineBuilder();
                    lineBuilder.MinY = descentY;
                    lineBuilder.MaxY = ascentY;
                    m_lineBuilders.Insert(lineBuilderIndex, lineBuilder);
                }
                lineBuilder = m_lineBuilders[lineBuilderIndex];
                var charGroup = lineBuilder.AddCharGroup(m_textRenderInfoSimple.OriginX);

                charGroup.OriginXPlusAdvancement = m_textRenderInfoSimple.OriginX + m_textRenderInfoSimple.Advancement;
                charGroup.Value            = text;
                charGroup.SingleSpaceWidth = renderInfo.GetSingleSpaceWidth();
                charGroup.CanBeSuperscript = lineBuilder.MinY < descentY && !IsCloseTo(lineBuilder.MinY, descentY) && IsCloseTo(lineBuilder.MaxY, ascentY);
            }
Exemplo n.º 11
0
        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;
        }