Skip to content

Guide

Cleaning text pasted from Word, Docs & PDFs

How to clean text pasted from Word, Google Docs, and PDFs — fixing smart quotes, hidden characters, and broken line wraps.

7 min read · updated

Text copied from Word, Google Docs, or a PDF rarely arrives clean. It carries smart quotes that break code, invisible characters that survive search-and-replace, and line breaks that turn a paragraph into a ragged column. None of this is visible at a glance, which is exactly why it causes trouble downstream. Here is what actually goes wrong and how to fix each case.

Smart quotes and typographic punctuation

Word and Docs replace straight quotes with curly ones as you type — “like this” instead of straight quotes — and turn double hyphens into em dashes and three dots into an ellipsis character. For prose that is fine, and often desirable. It becomes a problem the moment the text moves somewhere that expects plain ASCII: a code snippet, a CSV, a command line, a JSON string, or a search box.

The failure is confusing because the text looks right. A password with a curly apostrophe will not match the one you typed with a straight one. A JSON file with smart quotes will not parse. Straightening the punctuation converts every curly quote, dash, and ellipsis back to its plain equivalent without touching your words.

Text CleanerStraighten curly quotes, dashes, and ellipses when the text is heading somewhere that expects plain ASCII.

Hidden and zero-width characters

This is the category that wastes the most time, because the characters are invisible. Non-breaking spaces look identical to ordinary spaces but behave differently and break word wrapping. Zero-width spaces and joiners have no width at all, yet they sit inside your text, splitting words as far as a search function is concerned and inflating character counts.

Symptoms worth recognising: a find-and-replace that refuses to match a word you can plainly see; two strings that look identical but compare as different; a word count that is higher than it should be; a stray space you cannot delete with the backspace key. All of these point to invisible characters.

  • Non-breaking space (U+00A0): common in text from Word and from web pages.
  • Zero-width space (U+200B): often introduced by PDFs and some content systems.
  • Zero-width joiner and non-joiner: used in emoji and some scripts, but stray ones cause trouble.
  • The BOM (byte-order mark, U+FEFF): a leftover from file encoding that can appear at the very start of pasted text.
  • Soft hyphens: invisible until a word wraps, then they surface as an unexpected hyphen.
Text CleanerRemove zero-width and control characters so search, comparison, and word counts behave as expected.

Broken line wraps from PDFs

PDFs are the worst offenders. A PDF has no concept of a flowing paragraph — it stores lines at fixed positions on a page. When you copy a paragraph, you get a line break at the end of every visual line, so a single paragraph arrives as a dozen short lines. Paste that into an email or a document and it stays stubbornly ragged, refusing to reflow to the new width.

The fix is to remove the line breaks inside each paragraph while keeping the blank lines that separate one paragraph from the next. Removing every break would fuse the whole document into one line; keeping paragraph breaks preserves the structure while letting the text flow again.

Remove Line BreaksChoose the mode that keeps paragraph breaks to reflow PDF text without fusing separate paragraphs together.

Watch for hyphenated words split across lines. A PDF may break a long word at the margin, leaving a stray hyphen when the two halves rejoin. Check for leftover hyphens after reflowing, especially in text copied from a justified, narrow column.

Stray whitespace and inconsistent spacing

Pasted text often carries doubled spaces, tabs where you expected spaces, trailing spaces at the end of lines, and a mix of line-ending conventions from different platforms. These are the sort of thing that passes unnoticed until the text lands in a system that cares — a code editor, a database import, or a template that renders the extra space visibly.

  • Collapse runs of repeated spaces down to one.
  • Trim spaces and tabs from the start and end of each line.
  • Convert tabs to spaces, or the reverse, so indentation is consistent.
  • Standardise line endings to LF or CRLF, depending on where the text is going.
Whitespace CleanerTrim, collapse repeated spaces, and normalise tabs and line endings when spacing has to be consistent.

A sensible order to clean in

Order matters, because one step can create work for the next. A reliable sequence is: first reflow the line breaks so the paragraphs are whole again; then remove hidden and zero-width characters; then straighten smart quotes if the destination needs plain ASCII; and finally normalise the whitespace. Cleaning whitespace before you have joined broken lines just tidies text you are about to restructure anyway.

Finally, a note on where this happens. Cleaning runs entirely in your browser, so the document — which might be an unpublished manuscript, a contract, or confidential notes copied out of a PDF — is not uploaded to a server to be processed. The text goes in, the cleaned version comes out, and nothing leaves the page.

Tools in this guide

Search NeatKit

Jump to a tool, a page, or change the theme.