Trim Line Ends: Cleaning the Indentation That Comes with PDF Copy
Spaces and tabs at the start and end of every line are removed, while spaces inside a line and the blank lines between paragraphs stay. Pasted back into an editor, the mysterious indentation and quote marks stop appearing.
When line ends need cleaning
Copy a paragraph out of a PDF and each line often starts with a few spaces. Copy from an email or a web page and the ends may carry invisible spaces. Pasted into Markdown, four leading spaces become a code block and one space before a greater-than sign becomes a quote, so the output is nothing like what you meant.
Another case is a column exported from a spreadsheet: cells arrive with spaces around the value, and then sorting and lookups fail because Jane and Jane with a trailing space are two different values to the system. Clean the column once and dedupe or compare afterwards.
- Paragraphs copied from PDFs, emails, and web pages
- Spreadsheet exports with padded fields
- Removing trailing whitespace before committing code
How to trim without collateral damage
Only spaces and tabs at the beginning and end of each line are touched. Spaces inside a line are left alone, so alignment padding and the parts of code indentation you wanted to keep survive. Blank lines have nothing to trim and pass through, so paragraph breaks do not disappear.
Note that the full-width space (U+3000) is outside the scope. If the indentation came from a Japanese or Chinese page and uses full-width spaces, it stays, and the result looks cleaned but is not. Replace those with normal spaces in an editor first, then run this tool.
- Full-width spaces survive and need replacing first
- Inner spaces are kept, so alignment is unaffected
- Markdown hard breaks made with two trailing spaces are lost
Where it stops, and what to use instead
It only removes whitespace. It does not collapse runs of spaces inside a line, delete blank lines, or change indentation levels. For collapsing spaces use a whitespace-cleanup step, for blank lines use a dedicated tool, and for consistent indentation use your language's formatter.
There is one side effect worth knowing: Markdown hard line breaks made with two trailing spaces are exactly the characters being trimmed, so they stop working. If your document relies on them, switch to a trailing backslash or a blank line before running this.
- Does not collapse inner spaces
- Does not delete blank lines
- Breaks Markdown two-space hard line breaks
FAQ
Does it remove full-width spaces?
No. Only ASCII spaces and tabs are trimmed, so the full-width space (U+3000) common on Japanese and Chinese pages survives. To clear those, replace them with normal spaces in an editor first, then run this tool.
Will the blank lines between paragraphs disappear?
No. Blank lines have no content to trim and stay as they are. Do note that Markdown hard breaks made with two trailing spaces will break, because those spaces count as trailing whitespace; switch to a backslash or a blank line instead.
Are multiple spaces inside a line merged into one?
No. The tool only touches the start and end of each line, so runs of spaces inside a line stay exactly as they were. To merge them, run a separate whitespace-collapsing step, or use a regex replace in your editor.
Related tool:Trim Line Ends