Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using pdftotext (part of poppler-utils) to convert PDF documents to text. It works, for the most part, but one thing I wish it did was to insert blank lines between separate paragraphs instead of mashing them together.

Is there way to get pdftotext to do this? And if not, is there another pdf to text utility that can do this?

share|improve this question
In the title you say "pdftotext" (which is part of poppler-utils) and in the body you say "pdt2text" (which I don't know). Which you are you referring to? – enzotib Jul 6 '11 at 17:53
If you are looking for an online converter from PDF to text, I suggest trying It is a free and easy to use platform. Let me know if you find it useful! Thanks. – Julliana Aug 5 '14 at 9:36
up vote 16 down vote accepted

You could try ebook-convert from Calibre.

If anything, I'd say it errs in the other direction: too many line breaks.

Another thing I'd definitely consider though is converting to HTML using pdfreflow, and then convert the HTML to TXT.

share|improve this answer
+1 for pdfreflow – Stefan Schmidt Nov 22 '13 at 19:38

If you are using pdftotext you can use the -layout flag to preserve the layout of the text on the pages in your input pdf file:

pdftotext -layout input.pdf output.txt
share|improve this answer
This is the best answer! – Kartik Oct 26 '13 at 11:22
There is also -table for table layouts specifically, works great. – P.Windridge Jun 4 '15 at 11:35
Nice. This is what I want. +1 – Yun Huang Jul 12 '15 at 15:29
hi, what is units of all floating type number <page id="1" bbox="0.000,0.000,432.000,648.000" rotate="0">? means what is unit of bbox ? – Vivek Sable Mar 10 at 10:07
I've frequently had problems converting PDF files containing tables. There's something weird about some PDF creation software, where the "reading order" of text jumps around the cells in the table, so the only way I've been able to extract data in any sensible order is to copy and paste, then fix it up in a text editor. This takes hours. The -layout option seems to fix this, thanks. – Huw Walters Jul 13 at 15:28

As a fan of open source (and automation) I hate to say this, but the best results I just got (on quite a large, complex PDF) were to open it in Adobe Reader, then choose File|Save As Text.

(I am pre-processing for text analysis experiments, not as a reader, but I think my first and second choice would be the same.)

I've been comparing the output side-by-side. My second choice is ebook-convert.

Adobe: left in FF for page breaks, left in page numbers, hasn't converted headings/paragraphs to single lines, but it has fixed hyphens. Junk that was hidden in the PDF did not get output. Correctly got the big capitals at start of sections, e.g. "The", not "T he" or even "T he".

ebook-convert: Left in page numbers, and some hidden junk in header/footer (but no FFs). Converts most paragraphs to be single lines. The ones it missed are double-spaced though! Bullets don't always line up with the text. Correctly got "The" at the start of the chapter.

pdftotext (without --layout): Not bad, bullets line up, but header/footer noise. FFs are in there. Hyphens removed. Worst for start of chapter big letters: "T\n\nhe".

pdftotext (with --layout): Similar, but more indents. "T he" for start of chapter.

pdftohtml >> pdfreflow >> htmltotext: It removed page numbers, but still junk in header/footer. "T he" for start of chapter. Hyphens removed. (It uses multiple lines per paragraph, yet they are not the same line breaks as in the other versions!)

share|improve this answer

If you have a Google account, you can use Google Docs to upload the PDF and transform it into editable text.

share|improve this answer

I also tried pypdf and compared it against pdftotext on two documents. It had more linebreaks and split some section names (REFERENCES was R E F E R E N C E S).

pdf2txt did output complete garbage.

I often use pdfBox (java) if pdftotext screws up the output. You might give it a try.

share|improve this answer

protected by fossfreedom Mar 19 '15 at 7:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.