public override bool AllowText(TextRenderInfo renderInfo)
    {
        DocumentFont  font     = renderInfo.GetFont();
        PdfDictionary fontDict = font.FontDictionary;
        PdfName       subType  = fontDict.GetAsName(PdfName.SUBTYPE);

        if (PdfName.TYPE0.Equals(subType))
        {
            PdfArray      descendantFonts = fontDict.GetAsArray(PdfName.DESCENDANTFONTS);
            PdfDictionary descendantFont  = descendantFonts[0] as PdfDictionary;
            PdfDictionary fontDescriptor  = descendantFont.GetAsDict(PdfName.FONTDESCRIPTOR);
            PdfStream     fontStream      = fontDescriptor.GetAsStream(PdfName.FONTFILE2);
            byte[]        fontData        = PdfReader.GetStreamBytes((PRStream)fontStream);
            MemoryStream  dataStream      = new MemoryStream(fontData);
            dataStream.Position = 0;
            MemoryPackage        memoryPackage = new MemoryPackage();
            Uri                  uri           = memoryPackage.CreatePart(dataStream);
            GlyphTypeface        glyphTypeface = new GlyphTypeface(uri);
            ICollection <string> names         = glyphTypeface.FamilyNames.Values;
            return(names.Where(name => name.Contains("Arial")).Count() > 0);
        }
        else
        {
            // analogous code for other font subtypes
            return(false);
        }
    }
Beispiel #2
0
            public virtual void EventOccurred(IEventData data, EventType type)
            {
                switch (type)
                {
                case EventType.RENDER_TEXT: {
                    TextRenderInfo textInfo = (TextRenderInfo)data;
                    int            mcid     = textInfo.GetMcid();
                    if (mcid != -1)
                    {
                        ITextExtractionStrategy textExtractionStrategy = this.contentByMcid.Get(mcid);
                        if (textExtractionStrategy == null)
                        {
                            textExtractionStrategy = new LocationTextExtractionStrategy();
                            this.contentByMcid.Put(mcid, textExtractionStrategy);
                        }
                        textExtractionStrategy.EventOccurred(data, type);
                    }
                    break;
                }

                default: {
                    break;
                }
                }
            }
Beispiel #3
0
        //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));
        }
Beispiel #4
0
 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);
 }
Beispiel #5
0
        public void RenderText(TextRenderInfo renderInfo)
        {
            var text = renderInfo.GetText();

            _token.Append(text);
            _token.Append(" ");
        }
Beispiel #6
0
 /// <summary>
 /// Must be called by theme.
 /// </summary>
 /// <param name="info"></param>
 public void SetTextInfo(TextRenderInfo info)
 {
     lock (syncRoot)
     {
         textRenderInfo = info;
     }
 }
        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);
        }
Beispiel #8
0
            //--------------------------------------------------------------------------------------------------
            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);
            }
        private Rectangle GetRectangleFromReaderInfo(TextRenderInfo renderInfo)
        {
            var bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
            var topRight   = renderInfo.GetAscentLine().GetEndPoint();

            return(new Rectangle(bottomLeft[Vector.I1], bottomLeft[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]));
        }
 public override void RenderText(TextRenderInfo renderInfo)
 {
     foreach (TextRenderInfo tri in renderInfo.GetCharacterRenderInfos())
     {
         base.RenderText(tri);
     }
 }
Beispiel #11
0
        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;
        }
Beispiel #12
0
            public override void RenderText(TextRenderInfo renderInfo)
            {
                base.RenderText(renderInfo);

                //GraphicsState gs = (GraphicsState)gsField.GetValue(renderInfo);//expensive???
                //Font font = new Font { Name = string.Join(", ", gs.Font.FullFontName[0]), Size = gs.FontSize };

                List <CharBox>         cbs  = new List <CharBox>();
                IList <TextRenderInfo> cris = renderInfo.GetCharacterRenderInfos();

                foreach (TextRenderInfo cri in cris)
                {
                    Vector  baseLeft = cri.GetBaseline().GetStartPoint();
                    Vector  topRight = cri.GetAscentLine().GetEndPoint();
                    float   x        = baseLeft[Vector.I1];
                    float   y        = topRight[Vector.I2];
                    CharBox cb       = new CharBox
                    {
                        Char = cri.GetText(),
                        R    = new System.Drawing.RectangleF
                        {
                            X      = x - pageSize.X,
                            Y      = pageSize.Height + pageSize.Y - y,//(!)basic positioning point is char's baseLine, not ascentLine
                            Width  = topRight[Vector.I1] - x,
                            Height = y - baseLeft[Vector.I2],
                        },
                        //Font = font
                    };
                    cbs.Add(cb);
                }
                CharBoxs.AddRange(cbs);
            }
        //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;
        }
Beispiel #14
0
            public override void RenderText(TextRenderInfo renderInfo)
            {
                base.RenderText(renderInfo);

                List <CharBox>         cbs  = new List <CharBox>();
                IList <TextRenderInfo> cris = renderInfo.GetCharacterRenderInfos();

                foreach (TextRenderInfo cri in cris)
                {
                    Vector  baseLeft = cri.GetBaseline().GetStartPoint();
                    Vector  topRight = cri.GetAscentLine().GetEndPoint();
                    float   x        = baseLeft[Vector.I1];
                    float   y        = topRight[Vector.I2];
                    CharBox cb       = new CharBox
                    {
                        Char = cri.GetText(),
                        R    = new System.Drawing.RectangleF
                        {
                            X      = x - pageSize.X,
                            Y      = pageSize.Height + pageSize.Y - y,//(!)basic positioning point is char's baseLine, not ascentLine
                            Width  = topRight[Vector.I1] - x,
                            Height = y - baseLeft[Vector.I2],
                        },
                        //Font = font,
                        //FontSize = fontSize
                    };
                    cbs.Add(cb);
                }
                CharBoxs.AddRange(cbs);
            }
Beispiel #15
0
        private static ITextChunkLocation GetLocation(TextRenderInfo tri)
        {
            LineSegment baseline = tri.GetBaseline();

            return(new TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), tri.GetSingleSpaceWidth
                                                       ()));
        }
Beispiel #16
0
 public override void EventOccurred(IEventData data, EventType type)
 {
     if (type.Equals(EventType.RENDER_TEXT) || type.Equals(EventType.RENDER_IMAGE))
     {
         String tagName = GetTagName(data, type);
         if ((tagName == null && layerName == null) || (layerName != null && layerName.Equals(tagName)))
         {
             if (type.Equals(EventType.RENDER_TEXT))
             {
                 TextRenderInfo renderInfo = (TextRenderInfo)data;
                 SetFillColor(renderInfo.GetGraphicsState().GetFillColor());
                 SetPdfFont(renderInfo.GetGraphicsState().GetFont());
                 base.EventOccurred(data, type);
             }
             else
             {
                 if (type.Equals(EventType.RENDER_IMAGE))
                 {
                     ImageRenderInfo renderInfo = (ImageRenderInfo)data;
                     Matrix          ctm        = renderInfo.GetImageCtm();
                     SetImageBBoxRectangle(new Rectangle(ctm.Get(6), ctm.Get(7), ctm.Get(0), ctm.Get(4)));
                 }
             }
         }
     }
 }
Beispiel #17
0
        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.I1];
            _with1.PosRight  = renderInfo.GetAscentLine().GetEndPoint()[Vector.I1];
            _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);
        }
Beispiel #18
0
 public void RenderText(TextRenderInfo renderInfo)
 {
     foreach (TextRenderInfo info in renderInfo.GetCharacterRenderInfos())
     {
         this.textextractionstrategy.RenderText(info);
     }
 }
 virtual public void RenderText(TextRenderInfo renderInfo)
 {
     foreach (TextRenderInfo glyphInfo in renderInfo.GetCharacterRenderInfos())
     {
         deleg.RenderText(glyphInfo);
     }
 }
        private string GetTextFromRectangle(Rectangle rectangle)
        {
            string rectText = String.Empty;

            TextRegionEventFilter          textRegionEventFilter = new TextRegionEventFilter(rectangle);
            LocationTextExtractionStrategy extractionStrategy    = new LocationTextExtractionStrategy();

            foreach (IEventData textRender in textRenderList)
            {
                if (textRegionEventFilter.IsInsideRectangle(textRender, EventType.RENDER_TEXT))
                {
                    extractionStrategy.EventOccurred(textRender, EventType.RENDER_TEXT);
                }
                else if (textRegionEventFilter.Accept(textRender, EventType.RENDER_TEXT))
                {
                    TextRenderInfo         textRenderInfo = (TextRenderInfo)textRender;
                    IList <TextRenderInfo> renderInfoList = textRenderInfo.GetCharacterRenderInfos();
                    for (int index = 0; index < renderInfoList.Count(); index++)
                    {
                        if (textRegionEventFilter.IsInsideRectangle(renderInfoList[index], EventType.RENDER_TEXT))
                        {
                            extractionStrategy.EventOccurred(renderInfoList[index], EventType.RENDER_TEXT);
                        }
                    }
                }
            }
            rectText = extractionStrategy.GetResultantText();
            return(rectText);
        }
        /// <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);
        }
Beispiel #22
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);
        }
Beispiel #23
0
        public override void EventOccurred(IEventData data, EventType type)
        {
            if (!type.Equals(EventType.RENDER_TEXT))
            {
                return;
            }

            TextRenderInfo renderInfo = (TextRenderInfo)data;

            string curFont     = renderInfo.GetFont().GetFontProgram().ToString();
            float  curFontSize = renderInfo.GetFontSize();

            IList <TextRenderInfo> text = renderInfo.GetCharacterRenderInfos();

            foreach (TextRenderInfo t in text)
            {
                string letter  = t.GetText();
                Vector l_start = t.GetBaseline().GetStartPoint(),
                       l_end   = t.GetAscentLine().GetEndPoint();

                Rectangle l_rect = new Rectangle(l_start.Get(0), l_start.Get(1),
                                                 l_end.Get(0) - l_start.Get(0), l_end.Get(1) - l_start.Get(1));

                if (letter != " " && !letter.Contains(' '))
                {
                    TextResult.Add(new TextChunk()
                    {
                        Text       = letter,
                        Rect       = l_rect,
                        FontFamily = curFont,
                        FontSize   = curFontSize,
                    });
                }
            }
        }
Beispiel #24
0
            //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;
                }

                //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));
            }
        /// <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);
        }
Beispiel #26
0
 private TextChunkInfo(Vector startLocation, Vector endLocation, TextRenderInfo info)
     : base(info.GetText(), startLocation, endLocation, info.GetSingleSpaceWidth())
 {
     RenderInfo    = info;
     StartLocation = startLocation;
     EndLocation   = endLocation;
 }
Beispiel #27
0
        /// <summary>
        /// Renders portion of text (single character or set of same-width characters).
        /// </summary>
        /// <param name="renderInfo">render information</param>
        public void RenderText(TextRenderInfo renderInfo)
        {
            var charInfo = new CharRenderInfo(renderInfo);

            if (charInfo.value.Length == 0)
            {
                return;
            }

            var charWidth = charInfo.width / charInfo.value.Length;
            var x         = charInfo.x;
            var i         = 0;

            foreach (var c in charInfo.value.ToCharArray())
            {
                var info = new CharRenderInfo
                {
                    x        = x + charWidth * (i++),
                    y        = charInfo.y,
                    width    = charWidth,
                    height   = charInfo.height,
                    fontSize = charInfo.fontSize,
                    value    = c.ToString(System.Globalization.CultureInfo.InvariantCulture)
                };
                this.result.Add(info);
            }
        }
        /// <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));
        }
Beispiel #29
0
        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;
        }
Beispiel #30
0
 public void RenderText(TextRenderInfo renderInfo)
 {
     if (expectingTitle)
     {
         expectingTitle = false;
         File.WriteAllText(string.Format(format, imageNumber, "txt"), renderInfo.GetText());
     }
 }
Beispiel #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 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;
        }
 virtual public void RenderText(TextRenderInfo renderInfo) {
     foreach (TextRenderInfo glyphInfo in renderInfo.GetCharacterRenderInfos())
         deleg.RenderText(glyphInfo);
 }
Beispiel #33
0
 /**
  * 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;
 }
Beispiel #34
0
 /**
  * @param renderInfo
  * @return true if the text render operation should be performed
  */
 public virtual bool AllowText(TextRenderInfo renderInfo){
     return true;
 }
 /** 
  * @see com.itextpdf.text.pdf.parser.RenderFilter#allowText(com.itextpdf.text.pdf.parser.TextRenderInfo)
  */
 public override bool AllowText(TextRenderInfo renderInfo){
     return renderInfo.HasMcid(mcid);
 }
        /**
         * Displays text.
         * @param string    the text to display
         */
        private void DisplayPdfString(PdfString str){

            String unicode = Decode(str);

            //if (w.log) w._tr.WriteLine("RenderText : \"{0}\"", unicode);
            TextRenderInfo renderInfo = new TextRenderInfo(unicode, Gs(), textMatrix, markedContentStack);

            renderListener.RenderText(renderInfo);

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