Search code examples
pythonpdfpyperclip

Why doesn't this code remove newline characters from text copied to the clipboard?


I often copy text from PDFs into my notes and doing so almost always creates formatting issues. So to start, I'm just trying to create a simple script to remove newline characters from text copied to my clipboard.

Here's a LINK to the pdf I'm currently using.

I've tried this:

import pyperclip
text = pyperclip.paste()
new_text = text.strip()
pyperclip.copy(new_text)

I've also tried this:

import pyperclip
text = pyperclip.paste()
new_text = text.replace('\n', "")
pyperclip.copy(new_text)

I've read all of the related questions and answers on this subject but can't make it work.


Solution

  • Try also removing "\r". Some modules/programs don't adress the different types of line breaks in windows and other OSs