iSomor
Back to blog

Why does text copied from a PDF always come out messy?

5 min readFreed

You find a useful passage in a PDF and want to put it in your notes, share it with a colleague, or use it as material for a question. Select, copy, paste—it should take only a few seconds.

But after pasting, one sentence has been split across several lines, an English word breaks in the middle, and page numbers have appeared inside the paragraph. You only wanted to take out a passage; now you have to press Backspace again and again.

If the reading order is correct and only every line is broken, start by joining single line breaks inside paragraphs while keeping blank lines between paragraphs. Headings, lists, and hyphens at the end of a line need separate checks. If sentences from two columns are interleaved, fix the extraction order before deleting line breaks.

A line on the page is not necessarily a paragraph in the text

On a PDF page, a sentence wraps when it reaches the right edge. That visual break may only reflect the paper or column width; it does not necessarily mean the author started a new paragraph.

When you copy, the reader has to reorganize text from the page into a text stream, but it cannot always tell these two kinds of breaks apart. The text extraction guide for pdfminer.six explains how character positions and distances can be used to group characters into lines and text blocks. Content that looks connected on the page can still be split when copied.

Here are a few simple examples and ways to handle them.

Join the sentences, and keep the paragraphs

Start with a case that is relatively safe to clean up: each paragraph has been split into two lines, while a blank line remains between paragraphs.

Text to clean up:

We copied a paragraph
from the report into our notes.

The original page remains available
for checking names and numbers.

You can put the text above into iSomor Text Cleaner and follow these three steps:

  1. Paste the text. Put a short sample into “Original content” first, keeping the blank lines between paragraphs.
  2. Choose options and clean it up. Turn on “Merge single line breaks” and “Normalize spaces”. Leave “Join hyphenated words at line breaks” off for now, then click “Clean up text”.
  3. Check before taking the result. Compare both sides to make sure paragraphs and words were not joined incorrectly, then copy the text or download the TXT file.

Tool output:

We copied a paragraph from the report into our notes.

The original page remains available for checking names and numbers.

The break inside the sentence is gone, while the separation between the two paragraphs remains. The space between the English words is also preserved, so paragraph and from are not stuck together.

In this example, a single line break marks a line inside a paragraph and a blank line marks the paragraph boundary. If copying leaves only one line break between paragraphs, compare with the original and add the blank line before cleaning it up.

Do not remove every hyphen at a line break

In an English document, a word may be split at the end of a line because of the layout. For example:

The trans-
lation is ready for review.

Here trans- and lation are parts of the same word. With “Join hyphenated words at line breaks” enabled, the tool outputs:

The translation is ready for review.

But a similar appearance does not always call for the same treatment. Consider a word that was originally written as cross-validation:

We used cross-
validation to compare the models.

With the same option enabled, the actual output is:

We used crossvalidation to compare the models.

The line break is gone, but the meaningful hyphen has also been removed. Here, cross-validation should be kept.

So it is safer to leave hyphen joining off at first. Confirm that a word was split by the layout before using it. If the material contains compounds or model numbers, clean ordinary line breaks first and check hyphens one by one.

Headings and lists need some breathing room

Not every item that occupies its own line should be joined to the next line.

For example, the first line below is a heading, followed by an explanation and a list:

Preparation
Keep the original PDF first.

- Check names
- Check dates
- Check amounts

With “Merge single line breaks” and “Normalize spaces” enabled, the tool actually outputs:

PreparationKeep the original PDF first.

- Check names
- Check dates
- Check amounts

The list with - markers is preserved, but the heading and body have been joined. Once “Preparation” is plain text, without a font size or bold style, a single line break is not enough to identify it as a heading.

For this kind of material, add a blank line after the heading before cleaning it up. Using the same options again gives:

Preparation

Keep the original PDF first.

- Check names
- Check dates
- Check amounts

The blank line keeps the heading and body separate. For more complex nested lists, tables, or equations, keep them separate instead of merging them with ordinary paragraphs in one batch.

If the order is already wrong, do not rush to clean up line breaks

If a sentence from the left column is followed by text from the right column, or a page number appears in the middle of a sentence, deleting line breaks cannot fix the reading order. Go back to the copying step first:

  • Two columns are interleaved: Try selecting and copying one column or a small section at a time, then check the pasted order. If the reader still mixes the columns, try another extraction method.
  • Headers, footers, or page numbers are mixed in: Compare with the page and remove only the confirmed intrusions. Do not batch-delete every line containing a number; it may be a section number or data from the body.
  • A table has become a string of text: Check the headers, units, and row-column relationships before deciding whether it belongs in a plain-text note. Fewer spaces do not mean that the table has been restored.
  • The copied text is garbled: Check the text layer or font encoding separately. Formatting cleanup cannot correct those characters.
  • A scanned image has no selectable text: It needs OCR first. An existing OCR layer can still contain recognition errors; being able to copy text does not mean the text is accurate. pypdf’s documentation distinguishes digitally born PDFs, image-only scans, and PDFs with an OCR layer. Their text comes from different sources.

Before using the copied result, check these spots

After cleaning a short passage, look closely at the places most likely to change:

  • Did each paragraph keep the right beginning and ending?
  • Did English words remain separate, and did meaningful hyphens stay in place?
  • Are headings and lists still separated?
  • Are numbers, units, minus signs, and equation symbols complete and in the right place?

It is also worth scanning around Chinese punctuation if the passage contains it. In our test, merging a line break after a comma left an extra space that had to be removed by hand. Confirm that the method works for this short passage before applying it to similar material.

If you are going to quote the passage, keep the document title, page number, or link, and check the text against its source.

Clean it up so you can get back to what you were doing

The purpose of text cleanup is to remove some repeated line breaks and extra spaces—not to press everything into one paragraph. When body text is joined while headings and lists stay separate, the result is easier to use.

iSomor puts the original content and the result side by side so that you can see what changed. Once you have checked it, you can return to your notes, excerpt, or discussion and focus on the passage you wanted in the first place.