0
votes

Long paragraphs in Adobe Acrobat results in a line break when text is copied to clipboard and pasted in Word.

To deal with this, I manually paste the copied-text in Notepad ++ > select all > ctrl+J (join lines) > select all > Copy...... and then paste it into my Word document.

I would like to automate this join line using autohotkey as I have a large body of documents to go through. I can't seem to find any examples online in dealing with this directly within autohotkey script.

Ex.

Data structures with labeled axes supporting automatic or explicit data alignment.
This prevents common errors resulting from misaligned data and working with
differently-indexed data coming from different sources.

After manually joining in Notepad ++

Data structures with labeled axes supporting automatic or explicit data alignment. This prevents common errors resulting from misaligned data and working with differently-indexed data coming from different sources.
3
found an answer here: superuser.com/a/1109920/235752JinSnow

3 Answers

2
votes

This works:

#Persistent
OnClipboardChange("ClipChanged")
return

ClipChanged() {

    If (WinActive("ahk_exe AcroRd32.exe")) {
        For e, v in StrSplit(clipboard, "`n", "`r")
            x .= v " "
        clipboard := trim(x)
    }
}
1
votes

Try this:

#Persistent
return

    OnClipboardChange:
If WinActive("ahk_exe AcroRd32.exe")
{
    clipboard =
    Send, {Ctrl down}c{Ctrl up}{Esc}
        ClipWait
    clip := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
    clipboard = %clip%  
    StringReplace clipboard, clipboard, % "  ", % " ", A         ; replace double spaces with single spaces 
        ClipWait
    ControlClick, x0 y0, A
}
return

EDIT

Or this:

#Persistent
return

    OnClipboardChange:
If WinActive("ahk_class AcrobatSDIWindow")
{
    clipboard := ""
    Send, {Ctrl down}c{Ctrl up}{Esc}
        ClipWait
    clip := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
    StringReplace clip, clip, % "  ", % " ", A         ; replace double spaces with single spaces 
    clipboard := "" 
    clipboard = %clip% 
    ClipWait 2
    If !(ErrorLevel)
    {
        ToolTip, lines joined
        Sleep 500
        ToolTip
    }
}
return
0
votes

I added functionality considering lines ending with a hyphen.

Before:

This occurs in elec-
tricity generation
systems.

After:

This occurs in electricity generation systems.

Code:

#Persistent
return

    OnClipboardChange:
If WinActive("ahk_exe AcroRd32.exe")
{
    clipboard := ""
    Send, {Ctrl down}c{Ctrl up}{Esc}
        ClipWait
    clip := RegExReplace(clipboard, "(\S.*?)-\R(.*?\S)", "$1$2") ; strip line breaks with hyphen
    clip := RegExReplace(clip, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
    StringReplace clip, clip, % "  ", % " ", A ; replace double spaces with single spaces 
    clipboard := "" 
    clipboard = %clip% 
    ClipWait 2
    If !(ErrorLevel)
    {
        ToolTip, lines joined
        Sleep 500
        ToolTip
    }
}
return