The problem this solves
Text copied out of a PDF, an email client or a terminal arrives with a line break at the end of every visual line rather than every paragraph. Paste it into a document and it stays broken at the width of the original, ignoring the width it is now in.
Removing those breaks lets the text reflow properly. The [msm_tool slug="remove-line-breaks"] does that, and it offers a paragraph mode because the naive version destroys something you usually want to keep.
Paragraph mode is the one to use
Stripping every line break turns an entire document into one continuous block. Technically correct, and rarely what anyone meant.
Paragraph mode treats a blank line as a paragraph boundary: breaks within a paragraph are removed so the text reflows, and the blank lines between paragraphs survive. That is almost always the right behaviour for prose from a PDF.
Use the plain mode when you genuinely want one line — preparing a value for a single-line field, or flattening text for a CSV cell.
Watch the joins
Two things to check in the result, because both look fine at a glance:
- Missing spaces. If the source had no trailing space before each break, joining two lines gives
theend rather than the end. Scan for run-together words, particularly at the start of the document where you stop reading carefully.
- Hyphenated words. PDFs and typeset documents break words across lines with a hyphen. Removing the break leaves
hyphen- ated or hyphen-ated in the middle of a sentence. There is no reliable way to detect this automatically — a genuine hyphen and a line-break hyphen look identical — so it needs a read-through.
What else comes out of a PDF
Line breaks are usually not the only problem. Text extracted from a PDF commonly carries:
- Page headers and footers interleaved through the body, appearing every forty lines or so.
- Page numbers on their own lines.
- Non-breaking spaces and unusual space characters that look normal and break searches.
- Curly quotes and en dashes, which is fine unless something downstream expects plain ASCII.
- Text in the wrong order if the original had columns — the extraction reads across the page rather than down each column.
That last one is not fixable by removing line breaks and is worth checking before you spend time on the rest.
Windows line endings
Windows ends a line with a carriage return and a line feed. Text that has travelled between operating systems may carry both, one, or a mixture.
Removing only one of the pair leaves a stray character that displays as nothing in some places and as a visible artefact in others. If cleaned text still shows odd breaks or invisible characters, mixed line endings are the usual explanation.
Where line breaks are meaningful
Do not run this on:
- Poetry or lyrics, where the line shape is the work.
- Addresses, where each line is a field.
- Code in any language, and especially Python and YAML.
- Markdown, where a blank line separates paragraphs and two trailing spaces force a break.
- Anything column-aligned, where position is the delimiter.
Keep the original
The joins are not reversible — once two lines are one, nothing knows where the break was. Work from a copy, particularly on a long document where a run-together word two thirds of the way down will not be spotted until someone else reads it.