GetFont() публичный Метод

public GetFont ( ) : DocumentFont
Результат DocumentFont
Пример #1
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;
        }
Пример #2
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];
 }
            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;
            }
Пример #4
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;
        }
        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;
        }
Пример #6
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;
            }
        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;
        }