fixmint

Why text copied from a PDF breaks at every line

· 5 min read

Text copied from a PDF breaks at every line because a PDF does not store paragraphs. It stores each visible line as a separate piece of text placed at a fixed position on the page, so when you copy, the program has to guess where a sentence really ends. Most readers guess by putting a line break wherever the original line ended, and your paragraph falls apart into dozens of short lines.

Fix pasted textPasted text has broken lines — free, runs in your browserOpen →

Why PDFs break paragraphs

A word processor stores a paragraph as one long run of text, and the layout engine wraps it to the width of the page when it draws it. A PDF works the other way round. It is closer to a set of drawing instructions: put this string of words here, put the next string there. The line wrapping was decided when the file was made, and the file keeps the line positions rather than the paragraph structure.

When you select and copy, the reader has to rebuild a text flow from those positions. Many readers insert a line break at each visible line end, and they cannot always tell a line end inside a sentence from the end of a real paragraph. The result looks right on the page and wrong in a text box.

Three other things make it worse:

  • Hyphenated line ends. A word split as "inter-" at the end of one line and "national" at the start of the next is copied as two pieces with a break between them. Some readers keep the hyphen, some drop it, and some leave the break in place.
  • Columns. Two-column layouts can copy the whole left column first and then the right, or interleave lines from both columns in one run.
  • Headers, footers and page numbers. These are copied into the middle of a sentence when a paragraph crosses a page break.

The fix

The repair is a short sequence of rules, applied in order:

  1. Join lines that do not end a sentence. If a line ends with a lowercase letter, a comma or a word with no full stop, the next line almost always continues it.
  2. Keep a break where the original had a paragraph gap. A line that ends with a full stop, question mark or colon, and is followed by a short or indented line, often starts a new paragraph.
  3. Remove a hyphen at a line end only when it splits one word. "inter-" plus "national" becomes "international". A real compound such as "well-" plus "known" should become "well-known", so check the joined word against the sentence.
  4. Delete repeated headers, footers and page numbers that appear once per page.

Here is a worked example. This is what a copy often looks like:

The committee met on Tuesday to review
the budget. Three members asked for more
time, and the chair agreed to a short delay.

After joining the lines that continue a sentence, it reads:

The committee met on Tuesday to review the budget. Three members asked for more time, and the chair agreed to a short delay.

Paste the copy into fix pasted text and the joins are done in one pass. Then check for invisible characters that came along with the copy. Remove hidden characters shows what it finds before it changes anything, and the hidden characters guide explains where they come from.

Columns and tables

Columns are the hardest case. The safest route is to select one column at a time, rather than dragging across both. If the PDF has a single reading order, copy the whole page once and then check the first and last lines of each column. If the words from the two columns are mixed together, you will have to copy in pieces.

Tables are worse. A table copied from a PDF often comes out as one cell per line, so you must rebuild the rows yourself or paste into a spreadsheet using a tab or a fixed delimiter. For a table with more than a few rows, it is faster to use a text-extraction tool that keeps columns, and then clean the result.

When the PDF is a scan

If the PDF is a scan, there is no text to copy. Each page is a picture, so what you see is all there is. You need optical character recognition (OCR) first, and OCR brings its own errors, such as "rn" read as "m" or "0" read as "O". Check the recognised text against the original before you rely on it.

Edge cases

  • Poems, code and addresses have line breaks that matter. Join only the lines that are obviously wrapped, and leave the rest alone.
  • A soft return (a wrap) and a hard return (a real paragraph) can look identical once copied. Read the first paragraph after cleaning, and fix any joins that look wrong.
  • If the cleaned text does not match when you search for a word you can see, the copy probably brought invisible characters along. Compare the copy with the original to find the differences.
  • If you need to keep the original layout, copy into a document editor with a "paste as plain text" option rather than cleaning by hand.

Quick answers

Why does copied PDF text have a line break at every line?

A PDF stores each visible line as a separate piece of positioned text, so the copy keeps the line ends. The fix is to join lines that continue a sentence and keep breaks only at real paragraph gaps.

How do I stop hyphenated words from splitting?

Remove the hyphen only where the two halves form one word, such as "inter-" and "national". Keep it in real compound words such as "well-known", which you can check against the sentence.

Can I copy a table from a PDF into a spreadsheet?

Often, but usually only with a tab-separated or fixed-width copy. For tables with many rows, a text-extraction tool that keeps columns is quicker than fixing each cell.

Cover of How to Remain Valuable When Intelligence Becomes CheapHow to Remain Valuable When Intelligence Becomes Cheap

224 pages on the human, economic and strategic advantages that stay scarce when AI can do most cognitive work.

$3.84 Get it on Gumroad →