How to clean up text copied from a PDF or website
Fix broken lines, double spaces, curly quotes, invisible characters and leftover HTML in text copied from PDFs, emails and web pages.
· 6 min read
Text copied out of a PDF arrives with a line break at the end of every visual line, because a PDF stores positioned lines rather than paragraphs. Cleaning it up means rejoining those single breaks while keeping the blank lines that separate paragraphs, then normalising the spaces, quotes and invisible characters that Word, email and web pages add along the way.
The quickest route here: get the text out with PDF to text, paste it into the Text cleaner and leave Join broken lines (keep paragraphs), Straighten smart quotes, Strip HTML tags, Collapse spaces and Remove invisible characters ticked. The result updates as you type, and everything runs in your browser — confidential documents never leave your device.
The ways to clean text, and when each one makes sense
| Method | Good for | Watch out for |
|---|---|---|
| A browser tool like this one | One pass over a page or a chapter, with a visible before and after | Very long documents are limited by the browser's memory |
| A word processor's find and replace | Text you are already editing in Word or LibreOffice | Paragraph marks and line breaks are different characters |
| A code editor with regular expressions | Repeating the same clean-up on files, every week | A regex mistake is easy to make and hard to spot |
In Microsoft Word, Find and Replace understands ^p for a paragraph mark and ^l for a line break: replace ^p^p with a placeholder, then ^p with a space, then the placeholder back — that is the manual version of joining broken lines. Pasting without formatting is Ctrl+Alt+V → Unformatted Text on Windows, and Ctrl+Shift+V or Cmd+Shift+V in most browsers and in Google Docs. On macOS, TextEdit strips everything with Format → Make Plain Text (Shift+Cmd+T). On Windows, pasting into Notepad does the same. Both remove formatting, but neither rejoins lines, straightens quotes or deletes invisible characters.
1. Get the text out
PDF to text extracts every page at once, with optional page separators, and offers the result as a .txt download — faster and more complete than selecting page by page in a viewer. The text layer is read with pdf.js and reassembled from the position of each fragment, so multi-column articles and tables can come out in an order that does not match the visual layout.
If the output is empty, the PDF is a scan: it contains pictures of text and no text layer at all. That needs OCR, which these tools do not perform, so nothing here will recover the words. The guide How to extract text from a PDF covers the cases in more detail.
2. Rejoin the broken lines
Join broken lines replaces a single line break with a space and leaves double line breaks alone, so hard-wrapped lines are merged while paragraphs survive. One limitation is worth knowing: it can only keep paragraphs that are actually separated by a blank line. When a PDF separates paragraphs by a single break, like every other line, joining produces one long block and the paragraph breaks have to be put back by eye.
Turn the option off for code, tables and address lists, where each line break is meaningful.
3. Normalise spaces and invisible characters
Text from PDFs, Word and websites is full of characters that look like ordinary spaces but are not:
- Non-breaking spaces (U+00A0) look normal, yet a search for "New York" will not find "New" + NBSP + "York", and spreadsheet lookups fail on them.
- Zero-width characters — zero-width space, joiner and non-joiner, word joiner, byte-order mark — are completely invisible and are frequently pasted in from web pages.
- Soft hyphens (U+00AD) mark where a word may break. They are invisible until the text is reflowed, then a hyphen appears in the middle of a word.
- Double spaces after full stops, and trailing spaces at the end of lines.
Remove invisible characters in the text cleaner deletes the zero-width family and soft hyphens, and Collapse spaces reduces runs of whitespace to one space. A single non-breaking space between two words survives that, however, so when a lookup still fails, run the text through Remove extra spaces with Normalise non-breaking & invisible spaces ticked: it converts every exotic space to a normal one.
4. Straighten quotes for code and data
Curly quotes (“ ” ‘ ’ « ») are correct in published prose and break everything else: code, CSV files, JSON, and some database imports. Straighten smart quotes turns them into " and '. The separate Dashes & ellipsis → ASCII option replaces en dashes, em dashes and the minus sign with a hyphen and … with three dots; leave it off when the text is destined for print.
5. Tidy the lines
- Remove empty lines turns a spaced-out list into one item per line, ready to paste into a spreadsheet column.
- Remove duplicate lines is the quickest way to strip the header or footer that repeats on every extracted page.
- Word counter confirms what you ended up with — see How to count words for the rules different tools apply.
Common problems, and what they mean
Words are stuck together: "thereportshows". Some PDFs position each glyph individually and store no space characters at all. There is nothing to clean — the spaces were never in the file. Look for another source, such as an HTML version of the document.
Accented or special characters come out wrong. The PDF embeds a subset of a font without a correct character map, so the extracted codes do not match the letters on screen. The text is wrong at the source; no clean-up can repair it.
Hyphenated words are split: "recom- mendation". The PDF hyphenated the word at the end of a line. Joining the lines keeps the hyphen and adds a space. Search for "- " in the result and repair those spots by hand; automatic repair would also damage genuinely hyphenated words.
Copying is blocked in the reader. The document's permissions forbid copying. Those are instructions to the reader, not encryption, but a password-protected file has to be decrypted before its text can be read at all.
Two columns are interleaved. Extraction follows positions, not reading order. Select one column at a time in a PDF viewer, or accept the reordering work.
Bullets became strange symbols. List bullets are often drawn as characters from a symbol font. Delete them with a search and replace once the lines are joined.
Questions people ask
Is my text uploaded? No. Every one of these tools runs in your browser, which is why they are safe for confidential documents. The text tools keep working with the connection off; extracting from a PDF first fetches the PDF engine.
Why does a PDF break lines in the first place? A PDF describes where each line of text sits on the page. There is no paragraph object to copy, so a reader gives you exactly what it sees: separate lines.
Can I clean code with these tools? Yes, with Join broken lines switched off — line breaks carry meaning in code. Straightening quotes, on the other hand, is usually what you want.
Does it work on a phone? Yes, in mobile Safari and Chrome, though pasting long documents on a phone is awkward.
Can I compare the cleaned text with the original? Yes — see How to compare two texts.
What about text copied from an email? Same routine. Email adds > quote markers and hard-wrapped lines at 72 characters, which Join broken lines handles once the markers are removed.
Next steps
- Extract first, clean afterwards: PDF to text
- Fix spaces on their own: Remove extra spaces
- Check the result: Word counter
Tools used in this guide
- Text CleanerFix broken lines, smart quotes, HTML and hidden characters.
- Remove Extra SpacesCollapse double spaces, trim lines and remove hidden spaces.
- Remove Empty LinesDelete blank lines, including lines with only spaces.
- PDF to Text (Extract Text from PDF)Extract the text of a PDF as plain text.
- Remove Duplicate LinesDelete repeated lines from a list and keep the original order.
- Word CounterCount words, characters, sentences and reading time as you type.