How to clean text copied from a PDF and rename identifiers

Rebuild paragraphs broken by line breaks and convert names between camelCase, snake_case and other styles without mistakes.

Practical guideUpdated Approx. reading time: 3 min
On this page

Why copied text arrives broken

When copying from a PDF, an email or a multi-column page, each line usually ends with a break that does not exist in the original text. Pasted, the sentences are cut and hard to edit or translate.

Removing line breaks rebuilds the text. With the keep-paragraphs option, a blank line still separates blocks and only the lines inside each one are joined. It is the safest option for text with several paragraphs.

Reviewing the result

Words hyphenated at the end of a line are not rebuilt on their own and may remain as “pa- per”. A bulleted list or a pasted table loses its structure when joined. Review those cases before using the text.

Afterwards you can remove double spaces with Clean text, or find and replace a specific broken hyphen. If you need to check the final length, use the character counter.

Changing the style of a name

Each language has its conventions: camelCase in JavaScript, snake_case in Python and databases, kebab-case in URLs and CSS, and CONSTANT_CASE for constants. Converting a long list by hand is slow and error-prone.

The tool splits words on spaces, hyphens, underscores and case changes, and handles acronyms well: XMLHttpRequest reads as XML Http Request. With the All option you see the five styles and copy the one you need.

  1. Paste the copied text into Remove line breaks.
  2. Choose keep paragraphs and collapse spaces.
  3. Review broken hyphens, lists and tables.
  4. For variable names, use camelCase and snake_case converter.

Criteria for reviewing and delivering the result

When cleaning a long text, work in steps and keep a copy of the original. First remove line breaks, then double spaces and finally review broken hyphens. That way you know which step caused a problem if something goes wrong. For texts you will reuse often, such as reports from the same source, note the order of steps that works best and repeat it the same way every time.

TRY IT YOURSELF

Text from a PDF with two paragraphs

Select Try example: the text has sentences broken across three lines and a second paragraph separated by a blank line. Choose keep paragraphs and collapse spaces, and select Remove line breaks.

The result has exactly two blocks: each is a continuous paragraph with a blank line between them.

Switch to No space and check that the words stick together: that option only suits broken codes or keys. Go back to the first option for normal text.

View tool screenshot
Remove line breaks example using sample data
Snipshed screenshot in Chrome using the described example. Downloadable files contain fictitious data.