How to delete line breaks when copying and pasting PDF
import pyperclip
s = pyperclip.paste()
s = s.replace("\n", "")
s = s.replace("\r", "")
pyperclip.copy(s)
Introduce a module called pyperclip
to operate the clipboard. Get the clipboard with pyperclip.paste ()
.
Remove line feed code using replace ()
. If it is inconvenient if there are two types of characters to delete, " \ r "
" \ n "
, adjust accordingly.
Paste it to the clipboard with pyperclip.copy ()
.
I also tried using pyautogui
to automatically paste, but it wasn't useful because the execution speed was more than doubled. He said that he only needed to be able to operate the clipboard.
Convert to executable using pyinstaller
. Install from the command prompt.
pip install pyinstaller
Then type the following command to execute it.
pyinstaller filename--onefile
An exe file is created in the dist folder.
Reference: How to start the program quickly (set a shortcut key)
Right-click the created exe file and create a shortcut.
Place the shortcut file on the desktop (or the Start Menu folder or the Programs folder under it).
Open the properties of the shortcut. There is a shortcut key item, so enter any key (ctrl + alt + number, etc.) there.
By the way, if the window opens at runtime, it will be an obstacle, so select "Runtime size" and set it to "Minimize".
That's it. If it doesn't work with the registered key, restart it once.
Achieve the goal by registering with the macro button of the mouse. It took about 3 seconds to complete the execution, so the practicality is not so high. In that case, it can be said that the method of predecessor is fine.
After that, if it depends on the external macro function, it is not necessary to complete it with one command separately, so put the shortcut file name as one character and put it in the folder where the path passes → "type win + R, file name, enter It is also ant to register it as a "execute" macro. If anything, you can place it on the taskbar and start it with the shortcut of win + number. There is a theory that these are faster to execute.
There may also be a more normal and efficient way to remove line breaks.
Recommended Posts