title: Extract text from multiple PDFs and write to a single CSV
body: <p>I want to loop through all the PDFs in a directory, extract the text from each one using PDFminer, and then write the output to a single CSV file. I am able to extract the text from each PDF individually by passing it to the function defined <a href="https://stackoverflow.com/questions/26494211/extracting-text-from-a-pdf-file-using-pdfminer-in-python">here</a>. I am also able to get a list of all the PDF filenames in a given directory. But when I try to put the two together and write the results to a single CSV, I get a CSV with headers but no data.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import os
  pdf_files = [name for name in os.listdir("C:\\My\\Directory\\Path") if name.endswith(".pdf")] #get all files in directory    
  pdf_files_path = ["C:\\My\\Directory\\Path\\" + pdf_files[i] for i in range(len(pdf_files))] #add directory path
  
  import pandas as pd
  df = pd.DataFrame(columns=['FileName','Text'])
  
  for i in range(len(pdf_files)):
      scraped_text = convert_pdf_to_txt(pdf_files_path[i])
      df.append({ 'FileName': pdf_files[i], 'Text': scraped_text[i]},ignore_index=True)
  
  df.to_csv('output.csv')
  </code></pre>
  
  <p>The variables have the following values: </p>
  
  <pre><code>pdf_files: ['12280_2007_Article_9000.pdf', '12280_2007_Article_9001.pdf', '12280_2007_Article_9002.pdf', '12280_2007_Article_9003.pdf', '12280_2007_Article_9004.pdf', '12280_2007_Article_9005.pdf', '12280_2007_Article_9006.pdf', '12280_2007_Article_9007.pdf', '12280_2007_Article_9008.pdf', '12280_2007_Article_9009.pdf']
  
  pdf_files_path: ['C:\\My\\Directory Path\\12280_2007_Article_9000.pdf', etc...]
  
  Empty DataFrame
  Columns: [FileName, Text]
  Index: []
  </code></pre>
  
  <p>Update: based on a suggestion from @AMC I checked the contents of scraped_text in the loop. For the Text column, it seems that I'm looping through the characters in the first PDF file, rather than looping through each file in the directly. Also, the contents of the loop are not getting written to the dataframe or CSV.</p>
  
  <pre><code>12280_2007_Article_9000.pdf E
  12280_2007_Article_9001.pdf a
  12280_2007_Article_9002.pdf s
  12280_2007_Article_9003.pdf t
  12280_2007_Article_9004.pdf  
  12280_2007_Article_9005.pdf A
  12280_2007_Article_9006.pdf s
  12280_2007_Article_9007.pdf i
  12280_2007_Article_9008.pdf a
  12280_2007_Article_9009.pdf n
  </code></pre>