title: How to convert from PDF to TXT without unintended line breaks?
body: <p>I am trying to convert a very clean PDF file into txt file using python. I have tried using pyPDF2 and PDFMiner, both worked perfectly in text recognition.</p>
  <p>However, as in PDF the lines are wrapped, the extracted .txt file have unintended line break at the end: e.g line 1: &quot;is an account of the Elder /n Days, &quot;. There should not be a line break between the &quot;Elder&quot; and the &quot;days&quot;.</p>
  <p><a href="https://i.stack.imgur.com/DD15H.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DD15H.jpg" alt="txt file" /></a></p>
  <p>The PDF file:
  <a href="https://i.stack.imgur.com/Jgng4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jgng4.jpg" alt="enter image description here" /></a></p>
  <p>When edited with Acrobat, it can be clearly seen the original text in PDF contains no hard line break, and could be edited as a paragraph instead of single lines.
  <a href="https://i.stack.imgur.com/FvwIe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FvwIe.jpg" alt="enter image description here" /></a></p>
  <p>The Code I have tried (adapted from an answer from here: <a href="https://stackoverflow.com/questions/55220455/convert-from-pdf-to-text-lines-and-words-are-broken">convert from pdf to text: lines and words are broken</a>)</p>
  <pre><code>import io as io
  from io import StringIO
  from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
  from pdfminer.converter import TextConverter
  from pdfminer.layout import LAParams
  from pdfminer.pdfpage import PDFPage
  import os
  import sys, getopt
  
  #converts pdf, returns its text content as a string
  def convert(fname, pages=None):
      if not pages:
          pagenums = set()
      else:
          pagenums = set(pages)
  
      output = io.StringIO()
      manager = PDFResourceManager()
      converter = TextConverter(manager, output, laparams=LAParams())
      interpreter = PDFPageInterpreter(manager, converter)
  
      infile = open(fname, 'rb')
      for page in PDFPage.get_pages(infile, pagenums):
          interpreter.process_page(page)
      infile.close()
      converter.close()
      text = output.getvalue()
      output.close
      return text
  
  path='D:\Folder\File.pdf'
  a=convert(path)
  f=open(&quot;D:\Folder\File.txt&quot;,'a',encoding='utf-8')
  f.write(a)
  f.close()
  </code></pre>