title: Find certain text in PDF, then return page number found on to another section NOTE: Uses Docotic.pdf
body: <p>In the following code, the user will input a search string (barcodedata).  That string will then be truncated to the first 5 characters, and used as the jobnumber.  The jobnumber, is also the name of the pdf I will be scanning for the barcodedata.</p>
  
  <p>What I would like, is for the 'Find it' button to execute the below code, then return the value found to startpagedata.</p>
  
  <p>I can't tell if the program just isn't actually scanning the PDF for the search string, or if the value simply isn't returning to the program.</p>
  
  <pre><code>using BitMiracle.Docotic.Pdf;
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Diagnostics;
  using System.IO;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Web;
  using System.Windows.Forms;
  using Acrobat;
  
  namespace BarCodeReader
  {
      public partial class Form1 : Form
      {
          public string stringsToFind;
          public string pathtofile;
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void barcodedata_TextChanged(object sender, EventArgs e)
          {
              stringsToFind=barcodedata.Text;
              pathtofile = "C:\\" + StringTool.Truncate(barcodedata.Text, 5) + ".pdf";
              jobnumberdata.Text = StringTool.Truncate(barcodedata.Text, 5);
          }
  
          private void label4_Click(object sender, EventArgs e)
          {
  
          }
  
          private void jobnumberdata_TextChanged(object sender, EventArgs e)
          {
              jobnumberdata.Text = jobnumberdata.Text.TrimStart('0');
              Console.WriteLine(jobnumberdata.Text);
          }
  
          private void startpagedata_TextChanged(object sender, EventArgs e)
          {
              Console.WriteLine(startpagedata.Text);
          }
  
          private void piecesdata_TextChanged(object sender, EventArgs e)
          {
          }
  
          private void FindIt_Click(object sender, EventArgs e)
          {
              PdfDocument pdf = new PdfDocument(pathtofile);
              for (int i = 0; i &lt; pdf.Pages.Count; i++)
              {
                  string pageText = pdf.Pages[i].GetText();
                  int count = 0;
                  int lastStartIndex = pageText.IndexOf(stringsToFind, 0, StringComparison.CurrentCultureIgnoreCase);
                  while (lastStartIndex != -1)
                  {
                      count++;
                      lastStartIndex = pageText.IndexOf(stringsToFind, lastStartIndex + 1, StringComparison.CurrentCultureIgnoreCase);
                  }
  
                  if (count != 0)
                      startpagedata.Text = Convert.ToString(lastStartIndex);
              }
  
          }
      }
  
      public static class StringTool
      {
          /// &lt;summary&gt;
          /// Get a substring of the first N characters.
          /// &lt;/summary&gt;
          public static string Truncate(string source, int length)
          {
              if (source.Length &gt; length)
              {
                  source = source.Substring(0, length);
              }
              return source;
          }
  
          /// &lt;summary&gt;
          /// Get a substring of the first N characters. [Slow]
          /// &lt;/summary&gt;
          public static string Truncate2(string source, int length)
          {
              return source.Substring(0, Math.Min(length, source.Length));
          }
      }
  }
  </code></pre>