Pasting plain text from clipboard + removing line breaks?
Hi,
I found the following AHK syntax which is working amazingly in FastKeys interface in order to paste text without formatting.
StringReplace, str_temp, ClipBoard, __blahblahasdfasdf
ClipBoard := str_temp
Send ^v
Does anyone know it there is any way to adjust this AHK syntax (or even any other in-built workaround in FastKeys) to also paste removing line breaks + replacing them with spaces?
It would be handy when copying/pasting text from PDF files.
Many thanks!
I found the following AHK syntax which is working amazingly in FastKeys interface in order to paste text without formatting.
StringReplace, str_temp, ClipBoard, __blahblahasdfasdf
ClipBoard := str_temp
Send ^v
Does anyone know it there is any way to adjust this AHK syntax (or even any other in-built workaround in FastKeys) to also paste removing line breaks + replacing them with spaces?
It would be handy when copying/pasting text from PDF files.
Many thanks!
FastKeys comes with a "Paste without formatting" command that works great for me too. See the library.
But I am very interested as well in that "paste removing line breaks + replacing them with spaces", if it is possible.
Code: Select all
clipboard := clipboard
Send, ^{vk56} ;Ctrl V
This should replace all line breaks in the clipboard with spaces:
so you can try:
You can add temporary variable to preserve original clipboard (like str_temp in your case).
Also, when using FastKeys Clipboard manager (default Ctrl-Alt-V), you can hold Ctrl key to paste without formatting.
Code: Select all
StringReplace, clipboard, clipboard, `r`n, %A_Space%, All
Code: Select all
clipboard := clipboard
StringReplace, clipboard, clipboard, `r`n, %A_Space%, All
Send, ^v
Also, when using FastKeys Clipboard manager (default Ctrl-Alt-V), you can hold Ctrl key to paste without formatting.
Thanks for valuable information!
Going a step further, does anyone you know if it is possible to make an adjustment in order to preserve / not remove breaks when there is tabs or hard returns between paragraphs?
The idea is to adjust the line breaks inside same paragraph, but when there a new paragraph/session starts, the pasted text could keep some structure from the divisions of the original text.
I made available a text example in the following link:
Through AHK forum I accessed this code, but it seems not working as expected, or even the problem is in the PDF files formatting I've tested:
Going a step further, does anyone you know if it is possible to make an adjustment in order to preserve / not remove breaks when there is tabs or hard returns between paragraphs?
The idea is to adjust the line breaks inside same paragraph, but when there a new paragraph/session starts, the pasted text could keep some structure from the divisions of the original text.
I made available a text example in the following link:
Through AHK forum I accessed this code, but it seems not working as expected, or even the problem is in the PDF files formatting I've tested:
Code: Select all
#v::
; Trim leading/trailing white space from empty lines
Clipboard:=RegExReplace(Clipboard,"m)^[ \t]*$","`r`n")
; copied from http://ahkscript.org/docs/commands/StringReplace.htm
; Remove all blank lines from the text in a variable:
Loop
{
StringReplace, ClipBoard, ClipBoard, `r`n`r`n, --[ahkparagraphmarker]--, UseErrorLevel
if ErrorLevel = 0 ; No more replacements needed.
break
}
;Replace all new lines with a space topreventjoinedwords
StringReplace, ClipBoard, ClipBoard, `r`n, %A_Space%, All
; Remove all double spaces (useful for justified text)
Loop
{
StringReplace, ClipBoard, ClipBoard, %A_Space%%A_Space%, %A_Space%, UseErrorLevel
if ErrorLevel = 0 ; No more replacements needed.
break
}
; re-create paragraphs again
StringReplace, ClipBoard, ClipBoard,--[ahkparagraphmarker]--,`r`n`r`n, All
; remove any leftover remaining leading spaces
Clipboard:=RegExReplace(Clipboard,"m)^[ \t]*")
Send ^v
Return
Could you post a link to actual example page/text which you would like to copy/paste and the expected result?
Hi,
I made available a .PDF sample and a .DOC expected output in the following link:
Actually, I achieved this output by using the function "copy without format" from Adobe Acrobat, and them pasting using the AHK script I posted above. However, if I simple copy and then use the script, the expected output doesn't appear. Since other PDF programs don't have this Acrobat function "copy without format", I would really appreciate to know if there is a workaround to copy (ctrl + v) and then pasting using the AHK script, achieving the expected output (.DOC I made available).
By the way, is there any way to attach files direct in the forum, or should I share content through links?
Thanks for assistance!
I made available a .PDF sample and a .DOC expected output in the following link:
Actually, I achieved this output by using the function "copy without format" from Adobe Acrobat, and them pasting using the AHK script I posted above. However, if I simple copy and then use the script, the expected output doesn't appear. Since other PDF programs don't have this Acrobat function "copy without format", I would really appreciate to know if there is a workaround to copy (ctrl + v) and then pasting using the AHK script, achieving the expected output (.DOC I made available).
By the way, is there any way to attach files direct in the forum, or should I share content through links?
Thanks for assistance!
sorry, the link is not working.