Automatically quote a passage from a PDF

Problem: Sometimes when taking notes from a PDF file it is not enough to summarise, but you need a quotation.  While it is easy enough to copy and paste test from a PDF to your notes, this can become a hassle if (a) you want to clearly indicate it is a direct quotation (so you can quote it at a later date without having to worry if you summarised the author’s intentions correctly, for example), or, (b) you want to save page numbers, etc.

Solution: The following AutoHotKey script is to be run when in some PDF viewing software.  You hit the key combination (Ctrl-Win-Q, in this case) and the script copies the text to the clipboard (you don’t press Ctrl-C in addition), cleans up the text, adds quote-marks around the text, adds the page number from the PDF file, and then waits until you switch back to Word.  As soon as you Alt-Tab back to Word, the result is copied to the clipboard, so there is no need for a Ctrl-v either.

As you can see, the script uses portions of the cleanly-paste-badly-formatted-text script and the automatically-reference-source script.

    textBlock := RegExReplace(textBlock, "\r\n", " ")
    textBlock := RegExReplace(textBlock, "(?<=\.) +", "  ")
    textBlock := RegExReplace(textBlock, "(?<!\.) +", " ")
    textBlock = %textBlock% ; runs autotrim
    return textBlock    

SetTitleMatchMode, slow
WinGetActiveStats, Title, Width, Height, X, Y

pageNumber := 

if InStr(Title, "PDF-XChange Viewer") then
    controlTitle := "DSUI:CmdEdit1"
    ControlGetText, pageNumber, %controlTitle%, ahk_class DSUI:PDFXCViewer
if InStr(Title, "Foxit Reader") then
    controlTitle := "RichEdit20W1"
    ControlGetText, pageNumber, %controlTitle%, ahk_class classFoxitReader

clipboard :=
Send ^c
theClipboard := CleanTextBlock(clipboard)
if pageNumber = 
    clipboard = `"%theClipboard%`"
    clipboard = %pageNumber% `: `"%theClipboard%`"
WinWaitActive, - Microsoft Word
Send ^v
Send {Enter}


The result looks something like this:

4 : “I understand moral atrocity to be roughly equivalent to Marilyn McCord Adams’s definition of “horrendous evils,” namely as “evils the participation in which (that is, the doing or suffering of which) constitutes prima facie reason to doubt whether the pa1ticipant’s life could (given their inclusion in it) be a great good to him/her on the whole.””