Page 1 of 1

Copy text without new line + carriage return

Posted: Wed Apr 18, 2018 4:04 pm
by Timur Born
Hello.

Is there a way to copy text out of a PDF without line breaks (new line + carriage return)? Yesterday I had to copy a floating text consisting of columns around images and then needed to get rid of all the line breaks. I did this by copying the text to Notebook++ and then replacing all \n and \r with empty characters, but maybe there is an easier way?

Re: Copy text without new line + carriage return

Posted: Thu Apr 19, 2018 12:10 am
by TrackerSupp-Daniel
Hi Timur,
I think for the time being, your method is the simplest around. If I can find one to do this from directly within the editor I will come let you know :)

Re: Copy text without new line + carriage return

Posted: Fri Apr 20, 2018 5:48 pm
by David.P
Hi all,

I found that at least with some PDF's, copying the text "as Rich Text" for example via context menu, can copy entire paragraphs as continuous (flowing) text without new lines and/or carriage returns.

Hth & regards
David.P

Re: Copy text without new line + carriage return

Posted: Fri Apr 20, 2018 6:05 pm
by Paul - Tracker Supp
I'm not seeing any difference between copy and copy as rich text.

David - does it matter what document you copy from to get this difference?

All my copy/paste efforts past entire paragraphs appropriately. It sounds like Timur has a relatively complex layout?
Yesterday I had to copy a floating text consisting of columns around images and then needed to get rid of all the line breaks.
Does this happen the same way for you Timur on any document or is this a specific case?

Re: Copy text without new line + carriage return

Posted: Fri Apr 20, 2018 7:15 pm
by Timur Born
Two columns of text floating around a center image. It doesn't matter whether I copy as text or rich-text the lines are copied as seen in the original. In order to copy that to pure text in a more readable form I have to first remove the /n/r.

When I copy from Editor I also have to remove lots of "-" (words divided between lines) whereas Adobe Reader copies the text without the latter even when they appear in the original PDF. So for the time being I will use Adobe Reader to copy these kind of texts, because it saves me from removing the "-" on top of the /n/r.

Image

Re: Copy text without new line + carriage return

Posted: Fri Apr 20, 2018 7:25 pm
by Paul - Tracker Supp
Understood.

Do we have and or may we have that document to "play" with here?

Re: Copy text without new line + carriage return

Posted: Fri Apr 20, 2018 8:02 pm
by Timur Born
You can use the following PDF, it contains several pages of similar formatting and also contains lots of "-" separated lines.

http://www.ulisses-spiele.de/download/2 ... a_261d.pdf

Re: Copy text without new line + carriage return

Posted: Fri Apr 20, 2018 10:30 pm
by Paul - Tracker Supp
Thanks Timur

have a great weekend!

Re: Copy text without new line + carriage return

Posted: Wed Sep 04, 2019 10:09 am
by Timur Born
In the meantime I am using an Autohotkey script that automatically strips new line + carriage return when I paste text via ALT+CTRL+V instead of CTRL+V.

Re: Copy text without new line + carriage return

Posted: Wed Sep 04, 2019 11:22 am
by Tracker Supp-Stefan
Thanks for the tip Timur!

Cheers,
Stefan

Re: Copy text without new line + carriage return

Posted: Wed Sep 04, 2019 11:47 am
by Timur Born
This is the AHK code I am using. It specifically looks for different cases that may or may not warrant a new line + carriage return. So paragraphs should stay intact. It also removes dashes "-" that are used to break words in two lines. Last but not least, it replaces several space characters with a single one.

I shamelessly copied the code from another source and then did a few minor edits.

Code: Select all

Paste:

; Note for following code that `r`n = newline

;Code the paragraph breaks with a special combinations
StringReplace Clipboard, Clipboard, .`r`n, -.-, All
StringReplace Clipboard, Clipboard, ?`r`n, -?-, All
StringReplace Clipboard, Clipboard, !`r`n, -!-, All
StringReplace Clipboard, Clipboard, :`r`n, -:-, All
;StringReplace Clipboard, Clipboard, `r`n`r`n, -*-, All

;Remove a dash followed by newline, since that's probably a single word across a linebreak
StringReplace Clipboard, Clipboard, -`r`n, , All

;Replace a single newline with a space
;StringReplace Clipboard, Clipboard, %A_Space% `r`n, %A_Space%, All
;StringReplace Clipboard, Clipboard, `r`n, %A_Space%, All

;Replace multiple adjacent spaces with a single one
Clipboard := RegExReplace(Clipboard, "\s+" , " ")

;Replace the paragraph break codes with newlines
StringReplace Clipboard, Clipboard, -.-, .`r`n, All
StringReplace Clipboard, Clipboard, -?-, ?`r`n, All
StringReplace Clipboard, Clipboard, -!-, !`r`n, All
StringReplace Clipboard, Clipboard, -:-, :`r`n, All
;StringReplace Clipboard, Clipboard, -*-, `r`n, All

Send ^v ;paste

return

Re: Copy text without new line + carriage return

Posted: Wed Sep 04, 2019 11:49 am
by Will - Tracker Supp
Thanks Timur, I'm sure others will find that useful! :)