title: Extract pdf document with multi page
body: <p>I am using <strong>Amazon's Textract</strong> service for extracting tables, Forms from pdf documnets.
  The example provided at Github <a href="https://github.com/aws-samples/amazon-textract-code-samples/tree/master/src-csharp" rel="nofollow noreferrer">here</a> is working for single page document only. But as per demo provided by AWS they are able to extract multi page pdf docs as well.</p>
  
  <p>As per documentation we have to call same service for multi pages as well. But it is not working for me.</p>
  
  <p>All the examples provided by them are either in python or java.</p>
  
  <p>I am doing it in dotnet core. </p>
  
  <p>Any help?</p>
  
  <p>Here is my code.</p>
  
  <pre><code>public IActionResult FileExtract(string filename)
      {
  
          try
          {
              string lineText = "";
  
              string wordText = "";
              string fieldsText = "";
              string fieldsText2 = "";
              string tableText = "";
  
  
              // Extracting file in below code.
              var textractAnalysisClient = BuildTextractClient();
              var document = PrepareDocument(textractAnalysisClient, "FORMS", filename);
              document.Pages.ForEach(page =&gt;
              {
                  page.Lines.ForEach(line =&gt;
                  {
                      lineText += "&lt;button class='rawlabel'&gt;" + line.Text + "&lt;/button&gt;";
                      line.Words.ForEach(word =&gt;
                      {
                          wordText += word.Text;
                      });
                  });
                  page.Form.Fields.ForEach(f =&gt;
                  {
                      fieldsText += "&lt;div&gt;&lt;h5&gt;" + f.Key + "&lt;/h5&gt;&lt;p style='background-color:lightgray;width: 200px;padding: 6px;'&gt;"
                      + f.Value + "&lt;/p&gt;&lt;/div&gt;";
                  });
                  var key = "Phone Number:";
                  var field = page.Form.GetFieldByKey(key);
                  if (field != null)
                  {
                      fieldsText2 += "Key: " + field.Key + "  | Value: " + field.Value;
                  }
              });
  
              tableText = "&lt;table id='customers'&gt;";
              document = PrepareDocument(textractAnalysisClient, "TABLES", filename);
              document.Pages.ForEach(page =&gt;
              {
                  page.Tables.ForEach(table =&gt;
                  {
                      var r = 0;
                      table.Rows.ForEach(row =&gt;
                      {
                          r++;
                          tableText += "&lt;tr&gt;";
                          var c = 0;
                          row.Cells.ForEach(cell =&gt;
                          {
                              c++;
                              tableText += "&lt;td&gt;";
                              tableText += cell.Text + "&lt;/td&gt;";
                          });
                          tableText += "&lt;/tr&gt;";
                      });
                  });
              });
  
              tableText += "&lt;/table&gt;";
  
              objJsonResponse.fieldsText = fieldsText;
              objJsonResponse.fieldsText2 = fieldsText2;
              objJsonResponse.lineText = lineText;
              objJsonResponse.tableText = tableText;
              objJsonResponse.wordText = wordText;
              objJsonResponse.responsecode = 1;
              return Json(objJsonResponse);
          }
          catch (Exception ex)
          {
              this.objJsonResponse.responsecode = -1;
              this.objJsonResponse.error = "failed";
              return Json(this.objJsonResponse);
          }
      }
  
      static TextractTextAnalysisService BuildTextractClient()
      {
          var builder = new ConfigurationBuilder()
              .SetBasePath(Environment.CurrentDirectory)
              .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
              .AddEnvironmentVariables()
              .Build();
          var awsOptions = builder.GetAWSOptions();
          return new TextractTextAnalysisService(awsOptions.CreateServiceClient&lt;IAmazonTextract&gt;());
      }
  
      static TextractDocument PrepareDocument(TextractTextAnalysisService textractAnalysisClient, string type, string FormFile)
      {
          var task = textractAnalysisClient.StartDocumentAnalysis(BucketName, FormFile, type);
          var jobId = task.Result;
          textractAnalysisClient.WaitForJobCompletion(jobId);
          var results = textractAnalysisClient.GetJobResults(jobId);
          return new TextractDocument(results);
      }
  </code></pre>