Open Editor
Writing Tips
5 min read

Remove Line Breaks From Copied Text Without Merging Your Paragraphs

Why pasted text breaks mid-sentence, what the common fixes get wrong, and the Windows line-ending trap that leaves invisible characters behind.

You copy a paragraph from a PDF, paste it into an email, and every line ends in the middle of a sentence. The obvious fix is to replace the line breaks with spaces, and it mostly works, until it merges two paragraphs into one or leaves a word split in half. This post explains why the breaks appear, then compares three common fixes on the same sample text so you can see exactly what each one does.

Cleaning up pasted text? Paste it into ClearText Editor and edit it in your browser. Nothing is uploaded.

Why the Breaks Are There

A PDF is built to look the same everywhere, not to reflow. According to PDF toolkit vendor Apryse's documentation, reading order is not defined in the ISO PDF standard, and "there is no concept of sentence, paragraph, tables, or anything similar in a typical PDF file." Each viewer has to guess where lines and paragraphs are when you select text, so different viewers give different results. One bug report shows a PDF viewer on Linux pasting a selection as separate lines, while Chrome's built-in viewer and another viewer pasted the same selection as a heading and two paragraphs. If the breaks are everywhere, trying a different viewer is a quick first step.

Three Fixes, Tested on the Same Text

My test sample has 43 words in two paragraphs. It contains two hyphenated line ends: for- followed by est, a word the layout split, and well- followed by known, a real compound word. I ran each fix in Python 3.

FixParagraphs"forest""well-known"
Replace every line break with a space1 of 2 (merged), plus a double space"for- est" (broken)"well- known" (broken)
Replace single breaks, keep blank lines2 of 2 kept"for- est" (broken)"well- known" (broken)
Same, plus join a hyphen at a line end2 of 2 kept"forest" (fixed)"wellknown" (wrong)

The first fix turned the blank line between paragraphs into a double space and left a trailing space. The second keeps the structure by treating a blank line as the paragraph marker and only replacing breaks that stand alone.

From the text alone, "for-" followed by "est" and "well-" followed by "known" look identical: a hyphen at the end of a line. Any rule that joins them will be right for the first and wrong for the second, so the last step has to be a human reading the result.

The Windows Line-Ending Trap

Not every line break is the same character. According to Wikipedia, Windows uses a carriage return plus line feed (CR+LF), modern Unix-like systems including macOS use a line feed (LF), and classic Mac OS used a carriage return (CR). If you replace only \n in CR+LF text, the \r stays behind. In my test, that left 8 stray carriage returns, one per line. Normalizing CR+LF to LF first removed them all, and the paragraph structure survived. Many editors don't display these characters, so the damage can go unnoticed until a count or a search behaves oddly.

A Safer Routine

  • Try a different PDF viewer first. Some paste cleaner text than others.
  • Normalize line endings, then replace single line breaks and leave blank lines alone.
  • Search for hyphens at the end of a line and decide each one yourself. Search for - followed by a line break, not by a space.
  • Then clear extra spaces. See Why Removing Double Spaces Matters, and How to Remove All Blank Lines From Text if the opposite problem appears.

The honest summary: line breaks in copied PDF text are there because a PDF has no notion of a paragraph, and the standard fix of replacing every break with a space merges paragraphs and splits words. Treat the blank line as the paragraph marker, normalize Windows line endings first, and review hyphenated line ends by eye, because no automatic rule can tell "for-est" from "well-known".

For questions or inquiries contact us at info@cleartexteditor.com