Menu

How to remove line breaks when copying text from a PDF

Paste the copied text into the remove line breaks tool, keep the default "A space, keep paragraphs" option and copy the result: every line break inside a paragraph becomes a space, and blank lines between paragraphs stay.

Published

Text copied from a PDF usually keeps a line break at the end of every line as it appeared on the page, so a pasted paragraph turns into a column of short lines. To fix it, paste the text into the remove line breaks tool and keep the default option, “A space, keep paragraphs”. Each line break inside a paragraph becomes a single space, blank lines between paragraphs are kept, and you copy the result back out. If the PDF hyphenated words across lines, also tick “Rejoin words split by a hyphen at the end of a line (PDF)”. Everything runs in your browser, so the text is not uploaded.

Why PDF text breaks in the middle of sentences

A PDF is built to look the same on every screen and printer, and when you select text the copy follows the lines you see. Each visual line ends with a line break, even when the sentence carries on. Word processors, email apps and web forms then treat each of those breaks as a real one, so the text no longer reflows when the window or column changes width.

Three other problems often come with it:

  • Hyphenated words. Justified layouts split long words across lines (“infor-” at the end of one line, “mation” on the next). The copy keeps the hyphen and the break.
  • Stray spaces. Lines can end or start with spaces, and some PDFs use no-break spaces or tabs between words.
  • Missing paragraph breaks. Some PDFs copy with a blank line between paragraphs; many copy with none, so the paragraph ends look exactly like line ends.

Step by step: fix copied PDF text

  1. Copy the text from the PDF. In Preview on a Mac, Apple’s instructions are to choose Tools > Text Selection, drag over the text, then choose Edit > Copy.
  2. Paste it into the remove line breaks tool.
  3. Leave “Replace line breaks with” on A space, keep paragraphs.
  4. If you see words split as “para- graph” in the result, tick Rejoin words split by a hyphen at the end of a line (PDF).
  5. If the result still has double spaces or a space before a period, paste it into remove extra spaces, then copy the final text.

Here is a real run of steps 2 to 4 on a short passage, with the hyphen option ticked:

Most readers skim the first para-
graph and decide whether to keep
going. Put the answer there.

The second paragraph can give
the details and the exceptions.

becomes

Most readers skim the first paragraph and decide whether to keep going. Put the answer there.

The second paragraph can give the details and the exceptions.

Without the hyphen option, the first line comes out as “Most readers skim the first para- graph and decide…”.

Which option to choose

The tool has four choices under “Replace line breaks with”. The input for every row below was the same: two lines of one paragraph, a blank line, then two lines of a second paragraph.

Option What it does Use it for
A space, keep paragraphs Joins lines with a space; any blank line (even one containing only spaces) stays as a paragraph break Articles, reports, papers, contracts
A space Joins everything into one paragraph with single spaces A single paragraph, a form field, a social post
Nothing Deletes the breaks with no space, so “the” + “proposal” becomes “theproposal” Text split in the middle of a code, URL or long number
Custom text Trims each line, drops empty lines and joins the rest with your text (“, “ by default) Turning a column of names into a list

The “Nothing” option is rarely what you want for prose. Run on our test passage, it produced “The committee reviewed theproposal in detail and foundthat the budget…”, because PDF line breaks usually sit where a space was.

With “Custom text” and “; “ as the separator, the lines “Apples”, “Pears” and “Plums” become Apples; Pears; Plums. Typing \n in the custom box inserts a line break, so \n\n turns single lines into separate paragraphs.

How the tool decides: the rules

These rules come from the tool’s code, so you can predict the result before you paste.

  • Windows and old Mac line endings (CRLF and CR) are treated the same as a normal line break, and so are the Unicode line separator (U+2028) and next-line (U+0085) characters. A Unicode paragraph separator (U+2029) counts as a blank line.
  • Spaces around a break are absorbed. “ends here “ + line break + “ and” becomes “ends here and”, with one space.
  • A paragraph break is a line break, then a line that is empty or holds only spaces or tabs, then another line break. Two or more blank lines in a row still give one paragraph break.
  • Paragraph detection needs a blank line. If your copied text has no blank lines, the tool cannot tell where a paragraph ended, and “A space, keep paragraphs” gives the same single block as “A space”. Add an empty line at each paragraph start before you run it; the PDF on screen shows you where they go.
  • The hyphen option only joins a lowercase letter, a hyphen (the ordinary - or the Unicode hyphen U+2010), the line break and another lowercase letter. “infor-” + “mation” becomes “information”. “Google-” + “Bot” is left alone, and the hyphen stays as “Google- Bot”.
  • Soft hyphens are always joined. Some PDFs copy a split word with an invisible soft hyphen (U+00AD) at the line end instead of a visible one. The tool removes it and joins the two parts with no space in every mode, even with the hyphen option off, so “infor” + soft hyphen + “mation” becomes “information”.
  • Real hyphens are joined too. With the option ticked, “well-” + “known” becomes “wellknown”. The tool cannot know which hyphens belong to the word, so with the option ticked the status line reports how many were joined (“2 hyphenated words joined (check that the hyphens were not real)”). Search the result for compounds you expect (well-known, long-term, follow-up) and put their hyphens back.
  • Spaces inside a line are not touched by “A space, keep paragraphs” apart from runs of normal spaces, which become one. Tabs and no-break spaces stay; that is the job of the next tool.

Clean up the spaces afterward

After the breaks are gone, copied PDF text often still has odd spacing. The remove extra spaces tool has four options, the first three ticked by default: trim spaces at the start and end of lines, replace tabs with a space, turn non-breaking and other odd spaces into normal spaces, and (off by default) remove spaces before punctuation.

Before After (defaults) After (with “Remove spaces before punctuation”)
Total cost : $1,200 for the first year . Total cost : $1,200 for the first year . Total cost: $1,200 for the first year.

The middle column looks unchanged here because the line-break tool had already collapsed the double spaces; what the defaults changed was the no-break space between “for” and “the”, which is now a normal space. If text still behaves strangely when you search or count it, remove invisible characters lists and strips zero-width characters and soft hyphens.

Other ways to get clean text from a PDF

  • Open the PDF in Word. According to Microsoft, Word makes a copy of the PDF and converts it to a Word document, trying to match the original layout; the original PDF is not changed. Microsoft says this works best with files that are mostly text, such as business, legal or scientific documents, and that the result might not look exactly like the PDF. Pages that are mostly charts or graphics may come through as an image, with no editable text.
  • Find and replace in Word. Microsoft’s steps on Windows are Home > Editing > Replace, then Find what, Replace with and Replace All. This works for fixing a repeated pattern, but a simple replace cannot tell a line break inside a paragraph from one at the end, which is what “A space, keep paragraphs” handles.
  • When you cannot select text at all. Apple lists two reasons in Preview: the Text Selection tool is not selected, or the PDF requires a password before text can be selected or copied. A scanned page that is only an image has no text to copy until it is run through text recognition.

Check the result before you use it

Once the text is joined, a few quick checks catch most leftovers:

  • Search for “- “ (hyphen then space) to find split words the hyphen option skipped, such as words with a capital letter after the break.
  • Look where each page ended in the PDF. Page numbers, running headers and footnotes are copied as ordinary lines and get joined into the middle of a sentence; delete them.
  • For text in two columns, check that the copy did not mix lines from both columns. If it did, copy one column at a time.
  • If you are comparing your cleaned version with an earlier one, text compare shows exactly which words changed, and the word counter confirms nothing was lost.

If the pasted text came with fonts and colors from the PDF, paste it as plain text first; the guide to pasting without formatting covers the shortcuts for each app.

Questions

Why does text copied from a PDF have a line break at the end of every line?

The copy keeps the lines as they were laid out on the page, so each visual line ends with a line break even in the middle of a sentence. Pasting into Word, an email or a form then shows short, ragged lines.

How do I remove line breaks but keep the paragraphs?

In the remove line breaks tool, choose "A space, keep paragraphs" (the default). Lines are joined with a space, and any blank line in the text is kept as a paragraph break. If your copied text has no blank lines between paragraphs, add them by hand at the paragraph starts first.

How do I fix words split with a hyphen at the end of a line?

Tick "Rejoin words split by a hyphen at the end of a line (PDF)". It joins a lowercase letter, a hyphen, a line break and another lowercase letter, so "infor-" plus "mation" becomes "information". It also joins real compounds such as "well-" plus "known", so read the result.

Why are there double spaces after I remove the line breaks?

The tool already collapses spaces around each line break, but spaces inside a line, tabs and no-break spaces stay. Run the result through remove extra spaces to reduce every run to one normal space.

Can I stop the line breaks when I copy, instead of fixing them after?

Opening the PDF in Word on Windows converts it to an editable document, and Microsoft says this works best for files that are mostly text. The layout may not match the original, so the line-break fix is often quicker for a few paragraphs.

Sources