How to Fix Messy Text Copied From a PDF
Text copied from a PDF arrives with a line break after every printed line, words cut in two by hyphens, uneven spacing and, often, a page number in the middle of a sentence. To fix it, join the lines inside each paragraph with a single space, keep the blank lines that separate paragraphs, collapse the extra spaces, and then read the result once for the things no tool can decide for you.
The short route is to paste the text into the Text Cleaner, choose the PDF Copy preset and press Clean Text. The rest of this guide explains why the mess happens, what that preset does and does not touch, and how to deal with what is left.
Why PDF text comes out broken
A PDF describes finished pages. For each piece of text it records which characters to draw and where on the page to draw them. It does not need to record that eight lines form one paragraph, that a word was hyphenated only because it reached the margin, or that the number at the foot of the page is not part of the article.
When you select and copy, the PDF viewer works backwards from positions to text. It groups characters into lines, infers spaces from the gaps between characters, and puts a line break after each visual line. Viewers guess differently, which is why the same file can paste differently from two applications.
The breaks you receive are real line-break characters, and nothing marks them as mere wrapping. Line break vs paragraph break explains the distinction.
What goes wrong, and what can be repaired automatically
| Problem | What you see | Repaired automatically? |
|---|---|---|
| Hard-wrapped lines | A line break after every printed line | Yes, by joining the lines inside each paragraph |
| End-of-line hyphenation | informa- ending one line, tion starting the next |
Partly. A heuristic, off until you tick it |
| Extra and odd spaces | Double spaces, spaces at line edges, non-breaking spaces | Yes |
| Soft hyphens, zero-width spaces | Nothing visible, but search and matching fail | Yes, with the PDF Copy preset |
| Page numbers, running headers and footers | 14 or the document title in mid-paragraph |
No |
| Footnote markers | results3 where the page showed a superscript 3 |
No |
| Ligatures | fi as a single character, or a missing letter pair |
No |
| Reading order | Two columns interleaved, table cells jumbled | No |
Hard-wrapped lines
The repair is to replace each single line break with a space while treating a blank line as the boundary between paragraphs. That works only if the copied text has blank lines between paragraphs, and not every copy does. If yours has none, joining gives you one solid block, and you need to mark the boundaries first. Removing line breaks without losing paragraphs covers that case.
Words hyphenated at the end of a line
Typeset documents break long words at the margin. Copying keeps both the hyphen and the line break, so a plain join turns informa- and tion into informa- tion.
Both tools have an option called Rejoin words hyphenated across lines. It is deliberately conservative: it merges only when the line ends in a lowercase letter and a hyphen and the next line starts with lowercase letters, and it leaves a suspended hyphen such as pre- / and post-war alone. That repairs informa- / tion and does not touch Anglo- / American. What it cannot know is whether a hyphen was added by the typesetter or belongs to the word. well- / known meets the rule and becomes wellknown. This is why the option is off by default, and why its output needs reading.
Some PDFs also contain soft hyphens (U+00AD), invisible characters that mark where a word may break. One at the very end of a line is always dropped when lines are joined, and the two halves are closed up when the next line starts with a lowercase letter, whether or not the hyphen option is ticked. The PDF Copy preset removes the rest, along with zero-width spaces; invisible Unicode characters explains both.
Extra and odd spaces
The viewer decides where spaces are by measuring gaps. Justified text, where word gaps are stretched to fill the line, can copy with double spaces. Tightly set text can go the other way and lose a space (ofthe), or gain one inside a word (T ypography). Indented and centred lines bring leading spaces with them, and a document may use non-breaking spaces (U+00A0) to keep two words on one line.
The PDF Copy preset handles doubled spaces, spaces at the edges of lines and non-breaking spaces. It does not handle missing spaces or spaces inside words, because no whitespace rule can tell ofthe from a real word. Removing extra spaces and tabs covers the whitespace options one by one.
Page numbers, headers, footers and footnotes
A selection that crosses a page boundary picks up everything printed there: the page number, the running header or footer, sometimes the footnotes. They land in the middle of whatever paragraph continued onto the next page. Footnote markers lose their superscript styling and become ordinary digits attached to a word.
Neither tool removes any of this, and that is intentional. A line containing only 14 might be a page number or might be a figure you need. Delete these by hand, ideally before joining, while each one still sits on a line of its own.
If the same running header repeats on every page, the Text Cleaner’s Find & Replace option can take out every copy in one pass: put the header text in the Find field and leave the Replace with field empty. The spacing around each deletion is tidied for you, but the page number beside the header stays. To remove both where they share a line of their own, tick Use regular expression and search for a pattern such as ^\d+ Survey Handbook$, written as the line looks after cleaning. It matches the whole line whatever the number.
Ligatures and missing letters
Typeset fonts often draw letter pairs such as fi and fl as one joined shape. Copying may give you two normal letters, the single ligature character (fi, U+FB01), or occasionally a wrong character or nothing at all (ofce where the page said office).
A ligature character looks right but does not match a search for the two letters. The Normalize Unicode (NFC) option does not split it, because NFC leaves compatibility characters such as ligatures unchanged. Use Find & Replace instead: find fi, replace with fi, then run it again for fl. Letters that were dropped have to be retyped.
Columns and tables
In a two-column layout a viewer may read straight across both columns or take them in the wrong order. Tables tend to arrive one cell per line or with every cell run together. Text cleanup cannot restore reading order, so copy one column at a time. In Preview on a Mac, holding Option while you select text copies a vertical portion such as a single column.
A realistic before and after
This sample was copied across a page boundary. It has hard wraps, four hyphenated line ends, double spaces, and a page number with a running header.
Before
Field notes should be written up on the same day. Mem-
ory fades quickly, and details that seemed obvious in the
afternoon are often gone by the next morning. Use a well-
known template so that every entry has the same
12 Survey Handbook
headings. Record the date, the location and the weather
before anything else.
Photographs need a caption and a compass direction. With-
out them, a picture of one hillside looks much like an-
other.
After (PDF Copy preset, with Rejoin words hyphenated across lines ticked)
Field notes should be written up on the same day. Memory fades quickly, and details that seemed obvious in the afternoon are often gone by the next morning. Use a wellknown template so that every entry has the same
12 Survey Handbook
headings. Record the date, the location and the weather before anything else.
Photographs need a caption and a compass direction. Without them, a picture of one hillside looks much like another.
The wraps, the double spaces and three of the four split words are repaired. Three things are still wrong, and each needs a person:
wellknownwas a real compound. The heuristic could not tell, so the hyphen has to go back.12 Survey Handbookis a page number and running header. It survived as a paragraph of its own.- The first paragraph is split in two where the page ended.
After the read-through
Field notes should be written up on the same day. Memory fades quickly, and details that seemed obvious in the afternoon are often gone by the next morning. Use a well-known template so that every entry has the same headings. Record the date, the location and the weather before anything else.
Photographs need a caption and a compass direction. Without them, a picture of one hillside looks much like another.
With the hyphen option left off, the same passage reads Mem- ory, well- known, With- out and an- other: nothing wrongly merged, four splits to close by hand. And without the blank lines around the header, it is joined into the sentence as the same 12 Survey Handbook headings, which is easy to miss.
Two ways to run the repair
The PDF Copy preset
- Paste the copied text into the Input Text box of the Text Cleaner.
- Choose the PDF Copy preset. On top of the General Clean whitespace cleanup it trims both sides of each line, joins hard-wrapped lines while keeping paragraphs, and removes soft hyphens and zero-width spaces.
- If words are split at line ends, open Advanced Cleaning Options and tick Rejoin words hyphenated across lines in the Line Breaks group.
- Press Clean Text. A short summary lists what changed. For the sample above it reads
6 line breaks removed,4 hyphenated words rejoinedand21 extra spaces removed. - Read the result against the PDF, fix what is left, then use Copy or Download .txt.
The Remove Line Breaks tool
If joining is all you need, Remove Line Breaks is the smaller tool. Select Keep paragraph breaks, or tick Fix common PDF copy problems, which trims the edges of each line, collapses repeated spaces, converts non-breaking spaces, removes soft hyphens and switches to Keep paragraph breaks for you. Rejoin words hyphenated across lines is available there too, off by default. Then press Remove Line Breaks. With both boxes ticked, the sample above comes out exactly as it does with the preset. The one difference is that this tool does not remove zero-width spaces.
In both tools, a line that begins with a list marker (-, *, +, •, or a number followed by . or )) stays on its own line instead of being folded into the paragraph above. Both work on pasted text in your browser. Neither opens a PDF file, and nothing you paste is uploaded.
The read-through
Joining and de-hyphenation are heuristics, so read the result once against the PDF before you use it. Beyond the page numbers and merged compounds shown above, look for splits that were not merged (search for a hyphen followed by a space, as in Anglo- American), a heading joined to the paragraph beneath it, two paragraphs merged because no blank line separated them, and any figures that came from a table.
If the PDF is a scan, whatever text you can copy comes from character recognition. Misread characters are a separate problem that line-break and whitespace repair do not fix.
Sources
- UAX #14: Unicode Line Breaking Algorithm — Unicode Consortium
- UAX #15: Unicode Normalization Forms — Unicode Consortium
This guide was drafted with AI assistance and reviewed by the publisher. See the editorial policy for how guides are written and corrected.