title: IText won't read correctly PDF region
body: <p>I'm using <code>LocationTextExtractionStrategy</code> combined with a custom <code>ITextExtractionStrategy</code> class to read a PDF. With this code I can read documents portions based on coords without problems.</p>
  
  <p>Now I get a PDF that seems like the others but if I try to read it I get text like this:</p>
  
  <pre><code>2  D   80 D   8 1 M 13M2 R   V / 8  3B 3 3 710 022/F//0 R8 8        1 0 / 3
  </code></pre>
  
  <p>This is the code I'm using:</p>
  
  <pre><code>private static string ReadFilePart(string fileName,int pageNumber, int fromLeft, int fromBottom, int width, int height)
  {
          var rect = new System.util.RectangleJ(fromLeft, fromBottom, width, height);
          var pdfReader = new PdfReader(fileName);
  
          var filters = new RenderFilter[1];
          filters[0] = new RegionTextRenderFilter(rect);
  
          var strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filters);
          var pageText = PdfTextExtractor.GetTextFromPage(pdfReader, pageNumber, new LimitedTextStrategy(strategy));
  
          pdfReader.Close();
  
          return pageText;
  }
  
  private class LimitedTextStrategy : ITextExtractionStrategy
  {
  
          public readonly ITextExtractionStrategy textextractionstrategy;
  
          public LimitedTextStrategy(ITextExtractionStrategy strategy)
          {
              textextractionstrategy = strategy;
          }
  
          public void RenderText(TextRenderInfo renderInfo)
          {
              foreach (TextRenderInfo info in renderInfo.GetCharacterRenderInfos())
              {
                  textextractionstrategy.RenderText(info);
              }
          }
          public string GetResultantText()
          {
              return textextractionstrategy.GetResultantText();
          }
  
          public void BeginTextBlock()
          {
              textextractionstrategy.BeginTextBlock();
  
          }
          public void EndTextBlock()
          {
              textextractionstrategy.EndTextBlock();
  
          }
          public void RenderImage(ImageRenderInfo renderInfo)
          {
              textextractionstrategy.RenderImage(renderInfo);
          }
   }
  </code></pre>
  
  <p>I cannot share the PDF file due to sensitive data.</p>
  
  <p><strong>Update</strong></p>
  
  <p>If I change <code>LocationTextExtractionStrategy</code> with <code>SimpleTextExtractionStrategy</code> it recognize the full row without strange characters (PDF structure?).</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>I can now share the file! Problematic pages are 2° and 3°</p>
  
  <p><a href="https://www.dropbox.com/s/y53kkzuq68e526f/test.pdf?dl=0" rel="nofollow noreferrer">PDF file</a></p>
  
  <p><a href="https://www.dropbox.com/s/lxlfopo9prozlye/TestReadPDF.zip?dl=0" rel="nofollow noreferrer">Test solution to read the file</a></p>
  
  <p><strong>Update 3</strong></p>
  
  <p><a href="https://stackoverflow.com/users/1729265/mkl">mkl</a> pointed me in the right direction and I fixed adding <code>FistChar</code>, <code>LastChar</code> and <code>Widths</code> to all fonts with missing properties with default values.</p>
  
  <pre><code>private static PdfReader FontFix(PdfReader pdfReader)
  {
          for (var p = 1; p &lt;= pdfReader.NumberOfPages; p++)
          {
              var dic = pdfReader.GetPageN(p);
              var resources = dic.GetAsDict(PdfName.RESOURCES);
  
              var fonts = resources?.GetAsDict(PdfName.FONT);
              if (fonts == null) continue;
  
              foreach (var key in fonts.Keys)
              {
                  var font = fonts.GetAsDict(key);
  
                  var firstChar = font.Get(PdfName.FIRSTCHAR);
                  if(firstChar==null)
                      font.Put(PdfName.FIRSTCHAR, new PdfNumber(0));
  
                  var lastChar = font.Get(PdfName.LASTCHAR);
                  if (lastChar == null)
                      font.Put(PdfName.LASTCHAR, new PdfNumber(255));
  
                  var widths= font.GetAsArray(PdfName.WIDTHS);
  
                  if (widths == null)
                  {
                      var array=new int[256];
                      array=Enumerable.Repeat(600, 256).ToArray();
                      font.Put(PdfName.WIDTHS, new PdfArray(array));
                  }
              }
          }
          return pdfReader;
    } 
  </code></pre>