Code to replace formatting and new lines from PDF copied text (FOXIT READER) NOT WORKING ANYMORE

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sadasada
Posts: 9
Joined: 20 Aug 2020, 03:46

Code to replace formatting and new lines from PDF copied text (FOXIT READER) NOT WORKING ANYMORE

Post by sadasada » 24 Mar 2023, 10:02

<r>I regularly use to copy text from PDF documents. Since the PDF copied text is not like MS Word doc, the new lines breaks are copied exactly as they are in PDF document. <br/>
I have been using following code to replace formatting and new lines from PDF doc (FOXIT READER SPECIFICALLY). But with recent version of Foxit Reader, the code is not working anymore. <br/>
Now it does not replace formatting from PDF doc, nor it removes line breaks. I have tried to uninstall and re-instal older version of Foxit pdf reader. Strangely it works with old version but not newest (Version 12.1.0.15250). <br/>
This thing is very strange as text is copied to clipboard and is manipulated later. So version should not affect it. Following is the code. Any help will be highly appreciated. <br/>

Autohotkey Version: 1.1.36.02

<CODEBOX codebox="autohotkey" file="Untitled.ahk"><s>

Code: Select all

</s>#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
;#singleInstance force


;follwing script removes line breaks when copying text from foxit pdf viewer. It also capitalises the first word in new sentence after dot. 


F8::Pause



#persistent
OnClipboardChange:
If A_IsPaused     
Return 
sleep, 20 

IfWinActive, ahk_class classFoxitReader
 {
 
   if DllCall("IsClipboardFormatAvailable", "uint", 1) ; check if clipboard has copied a text 
	{
		StringReplace, Clipboard, Clipboard,  `r`n,%A_Space%, All
		StringReplace, Clipboard, Clipboard,-%A_Space%,, All
		Clipboard := RegExReplace(Clipboard, "`am)^\s*\w|\si\s|\b(?:[A-Z]\.){2,}|[.?!]\s\w", "$U0") ;This works with acronyms as well and doesn't capitalize after acronyms
	}
	
 }  
<e>
</e></CODEBOX></r>

ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Code to replace formatting and new lines from PDF copied text (FOXIT READER) NOT WORKING ANYMORE

Post by ahk7 » 24 Mar 2023, 16:57

If it works with older versions but not with newer/current version, this is most likely the cause
ahk_class classFoxitReader
Use the window spy (right click on the AutoHotkey tray menu) to find the new class name and update it.
It may be easier to use ahk_exe foxit.exe
(note that I don't know the name of the executable as I don't use foxit so make sure to use the correct name of course)

Post Reply

Return to “Ask for Help (v1)”