title: How do you write text extracted from PDF (using textract) to docx files in python
body: <p>I have several articles in a single pdf file and I am trying to separate those articles and write them to separate Docx files. I managed to separate them using regex but when I try to write them to docx files, it throws this error: ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters.</p>
  <p>My code is as follows:</p>
  <pre><code>my_path = &quot;/path/to/pdf&quot;
  
  newpath = textract.process(my_path)
  newpath2 = newpath.decode(&quot;UTF-8&quot;)
  
  result = re.findall(r'\d+ words(.*?)Document \w+', newpath2, re.DOTALL)
  
  
  save_path = &quot;/path/to/write/docx/files/&quot;
  
  for each in result:
      import time
      time=str(time.time())
      finalpath = (os.path.join(save_path, time))
      finalpath2 = finalpath+&quot;.docx&quot;
      mydoc = docx.Document()
      mydoc.add_paragraph(each)
      mydoc.save(finalpath2)
  </code></pre>