Skip to main content

Fix Formatting

Fix Line Breaks Copied From a PDF

CleanPastedText editorial · Updated

Text workbench

Paste your text to clean it

Cleaning mode

Joins lines broken by PDF wrapping into paragraphs and removes hidden characters. Keeps typography.

Try a real example

Each sample contains a problem you cannot see.

Original

Pasted text

0 chars · 0 words

Cleaned

Ready to copy

0 changes

Text stays in this browser

Same words · No AI rewriting · No content logging

Why does a PDF paste with a break on every line?

A PDF describes where each line of text sits on the page, not where paragraphs begin and end. When you copy, the viewer joins the fragments it finds and ends each visual line with a newline. The result is text that wraps at the width of the original page, with the wrong line lengths in your email, note or document.

Two problems get mixed together here, and they need different fixes: the hidden characters that come along (soft hyphens, odd spaces), and the hard-wrapped lines. The cleaner on this page handles both in Join Lines mode. If you would rather work in your own editor, the patterns in step 2 do the same job.

Step 1: paste into the cleaner in Join Lines mode

Paste the text into the cleaner. This page opens it in Join Lines mode, which removes soft hyphens and zero-width characters, converts non-breaking spaces to ordinary spaces, and then joins the lines inside each paragraph. The report shows how many line breaks it joined, so you can check the count against the PDF. More detail is on the PDF text cleaner page.

Step 2: or join the lines with a regex

GoalFind (regex)Replace with
Repair words split by a hyphen at line end(\w)-\n(?=[a-z])$1
Join lines inside a paragraph(?<!\n)\n(?!\n)One space

In JavaScript, run the first two in order: text.replace(/(\w)-\n(?=[a-z])/g, "$1").replace(/(?<!\n)\n(?!\n)/g, " "). Editors that support regular expressions (VS Code, Sublime Text, Notepad++ in regex mode) accept the same patterns.

Two honest limits apply to both these patterns and Join Lines mode. The hyphen rule will also join a genuine hyphenated word that happens to break at the hyphen, such as well-known, so skim the result. And if the PDF has no blank line between paragraphs, no pattern can tell where one paragraph ends, so you will need to mark paragraph breaks by hand first. Remove hidden characters before running the patterns, so they do not trip over a soft hyphen or an odd space.

Step 3: do it in Word or Google Docs

  • Word: open Find and Replace (Ctrl+H). Replacing ^p with a space also joins paragraphs, so first replace ^p^p with a placeholder such as @@, then replace ^p with a space, then swap the placeholder back to ^p^p.
  • Google Docs: Edit, Find and replace, tick "Match using regular expressions" for the hyphen pattern. Lookbehind patterns may not be supported there, so use the placeholder approach from the Word bullet to join lines.

What if the text still looks wrong?

Columns interleaved, page numbers in the middle of sentences, and scanned pages are layout and OCR problems. Copy one column at a time, use your PDF reader's export or Reading Mode where it exists, or run OCR on scans first. The wider background is in why text pastes weird and the general spacing fix.

Common questions

Frequently asked questions

Why does text copied from a PDF have a line break on every line?

A PDF is a page-layout format. It places each line of text at fixed coordinates and has no built-in concept of a paragraph. When a viewer copies the text, it usually ends each visual line with a newline, so your pasted text wraps at the width of the printed page instead of the width of your document.

How do I remove line breaks from PDF text but keep paragraphs?

Replace each single newline with a space, and leave a newline that is followed by another newline. In a regex-capable editor or in JavaScript, the pattern (?<!\n)\n(?!\n) matches a lone line break. This only works if your paragraphs are separated by a blank line, which many PDF viewers do not add.

Does CleanPastedText join PDF lines?

Yes, in Join Lines mode, which this page selects. It replaces each line break inside a paragraph with a space, keeps blank lines between paragraphs and lines that start a list item, and rejoins a word split by a hyphen when the next line starts with a lowercase letter. The other modes keep ordinary line breaks so lists, addresses and code are not merged by accident.

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

Join Lines mode removes soft hyphens (U+00AD) and rejoins a visible line-end hyphen only when the second half starts with a lowercase letter. In a regex editor, the pattern (\w)-\n(?=[a-z]) does the same. Review the result either way, because a real hyphenated word such as well-known that breaks at its hyphen would also be joined.

Why is there a space or odd character inside PDF words?

Some PDFs place letters as separate positioned fragments, and the viewer guesses where spaces belong. Others use ligature glyphs or non-breaking spaces. A cleaner can normalise the special spaces and hidden characters, but it cannot know the original spelling, so check names, numbers and words with ligatures such as fi.

Continue reading

Related guides & tools