title: Searching PDF for Underlined and Bolded text
body: <p>Using iTextSharp, how can I determine if a parsed chunk of text is both bolded and underlined?</p>
  
  <p>Details:<br>
  I'm trying to parse .PDF files in C# specifically for text that is both bolded and underlined.  Using ITextSharp, I can derive from LocationTextExtractionStrategy and get the text, the location, the font, etc. from the iTextSharp.text.pdf.parser.TextRenderInfo object passed to the overridden .RenderText method.<br>
  However, determining if the text is Bold and/Underlined from the TextRenderInfo object has not been straight forward.  </p>
  
  <ul>
  <li>I tried to use TextRenderInfo.GetFont() to find the font properties, but was unsuccessful</li>
  <li>I can currently determine if the text is Bold or not, by accessing the private Graphics State field on the TextRenderInfo object and checking it's .Font.PostscriptFontName property for the word "Bold"  (Ugly, but appears to work.)</li>
  <li>Biggest issue: I haven't found anything to determine if the text is underlined.  How can I determine this?</li>
  </ul>
  
  <p>Here is my current attempt:</p>
  
  <pre class="lang-c# prettyprint-override"><code>        private FieldInfo _gsField = typeof(TextRenderInfo).GetField("gs",
          BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance);
  
          //Automatically called for each chunk of text in the PDF
          public override void RenderText(TextRenderInfo renderInfo)
          {
              base.RenderText(renderInfo);
              //UNDONE:Need to determine if text is underlined.  How?
  
              //NOTE: renderInfo.GetFont().FontWeight does not contain any actual information
              var gs = (GraphicsState)_gsField.GetValue(renderInfo);
              var textChunkInfo = new TextChunkInfo(renderInfo);
              _allLocations.Add(textChunkInfo);
              if (gs.Font.PostscriptFontName.Contains("Bold"))
                  //Add this to our found collection
                  FoundItems.Add(new TextChunkInfo(renderInfo));
  
              if (!_lineHeights.Contains(textChunkInfo.LineHeight))
                  _lineHeights.Add(textChunkInfo.LineHeight);
          }
  </code></pre>
  
  <p>Full source code of current attempt at: <a href="https://github.com/SvdSinner/PdfParserSample" rel="nofollow noreferrer">GitHub Repository</a>  (Two examples (<a href="https://github.com/SvdSinner/PdfParserSample/blob/master/PDFParserLinker/example.pdf" rel="nofollow noreferrer">example.pdf</a> and <a href="https://github.com/SvdSinner/PdfParserSample/blob/master/PDFParserLinker/Example2.pdf" rel="nofollow noreferrer">example2.pdf</a>) are included with text similar to what I'll be searching through.)</p>