title: How to extract images Text from a PDF using iText 7
body: <p>I created a simple method that extract text from PDF file and inserts that text into a txt file.
  The issue, it only extracts the text of the pdf not the text from the images that are inserted in the PDF. I tried this <a href="https://itextpdf.com/en/blog/technical-notes/how-use-itext-pdfocr-recognize-text-scanned-documents#:%7E:text=iText%20pdfOCR%20accepts%20input%20from,text%20you%20need%20to%20access." rel="nofollow noreferrer">link</a> but did not understand how to implement.
  This code works fine if you are only interested in text.</p>
  <pre><code>//usings
  using iText.Kernel.Pdf;
  using iText.Kernel.Pdf.Canvas.Parser;
  using iText.Kernel.Pdf.Canvas.Parser.Listener;
  using System.IO;
  using System.Text;
  //code
   string file = @&quot;C:\test.pdf&quot;;
              string extension = Path.GetExtension(file);
              var pageText = new StringBuilder();
  
              if (extension == &quot;.pdf&quot;)
              {
                  using (PdfDocument pdfDocument = new PdfDocument(new PdfReader(file)))
                  {
                      var pageNumbers = pdfDocument.GetNumberOfPages();
                      StreamWriter sw = new StreamWriter(@&quot;C:\output.txt&quot;);
  
                      for (int i = 1; i &lt;= pageNumbers; i++)
                      {
                          LocationTextExtractionStrategy strategy = new LocationTextExtractionStrategy();
                          PdfCanvasProcessor parser = new PdfCanvasProcessor(strategy);
                          parser.ProcessPageContent(pdfDocument.GetFirstPage());
                          pageText.Append(strategy.GetResultantText());
                          string name = pageText.ToString();
                          sw.WriteLine(name);
                      }
                      sw.Close();
  
                  }
              }
  </code></pre>
  <p>I feel the issue is very simple but I can't figure it out.</p>