Find and copy text from PDF to clipboard

Get help with using AutoHotkey and its commands and hotkeys
aisvais
Posts: 4
Joined: 26 Sep 2017, 03:44
Google: Aistė Vaisėtaitė

Find and copy text from PDF to clipboard

26 Sep 2017, 04:58

Hello,

I am trying to find a way to write an AHK script for finding and copying number from PDF into clipboard.

Basically, I have a PDF file, one page per file. The field I need would look like this:

Comment
123456789


Field names never change. But there are other numbers in the file.

I would like to copy that number into the clipboard. Sometimes, the number can be longer or shorter, from 10 to 15 characters. Sometimes, the number can be inside a PDF comment.

I can turn a blind eye to the exceptions, so something to start with would be great too.


Thanks in advance for your ideas!
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Find and copy text from PDF to clipboard

26 Sep 2017, 05:34

Normally I would use RegExMatch, but the PDF part can be messy.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
aisvais
Posts: 4
Joined: 26 Sep 2017, 03:44
Google: Aistė Vaisėtaitė

Re: Find and copy text from PDF to clipboard

27 Nov 2017, 03:08

Sorry, I was sure I added my code:

Code: Select all

Send,^c
Clipboard := RegExReplace(Clipboard , "\s\s+", "")
StringReplace, clipboard, clipboard, -,, All
The thing is, I can do finding part manually. But the code keeps messing up with "-" removal. I launched the code three times for same instance and all three times there was a different result: 1. number not copied 2. number copied with - 3. number copied without -

I find it genuinely strange.
User avatar
Xeo786
Posts: 363
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Find and copy text from PDF to clipboard

27 Nov 2017, 05:51

aisvais wrote:Sorry, I was sure I added my code:

Code: Select all

Send,^c
Clipboard := RegExReplace(Clipboard , "\s\s+", "")
StringReplace, clipboard, clipboard, -,, All
The thing is, I can do finding part manually. But the code keeps messing up with "-" removal. I launched the code three times for same instance and all three times there was a different result: 1. number not copied 2. number copied with - 3. number copied without -

I find it genuinely strange.
use clipwait right after sending ^C .... data copying from pdf take time ...
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
aisvais
Posts: 4
Joined: 26 Sep 2017, 03:44
Google: Aistė Vaisėtaitė

Re: Find and copy text from PDF to clipboard

01 Dec 2017, 04:11

Thanks, I did not think of that! This has improved the code a lot.

So what I have now is:

Code: Select all

^+I::
Send,^c
ClipWait, 2
Clipboard:= RegExReplace(Clipboard,"\s\s+","")
StringReplace, clipboard, clipboard,-,,All
Send {F10}
Send F
Send {Down}{Down}{Down}{Down}{Down}
Send {enter}
Sleep 2000
Send, name
Send {enter}
Send {tab}
Send {tab}
sleep 100
Send subject
sleep 100
Send {tab}
Send {tab}
Send {Enter}
Send {Enter}
sleep 100
Send text
Send {Enter}
sleep 100
Send number=
sleep 100
Send,%Clipboard%
Sleep 300
Send,{Enter}
sleep 100
Send text
return
It is really basic and I have not much experience with AHK.
But it does what I need it to: when I am in pdf, I mark the number I want to copy and then launch the code. Then from Adobe Reader it launches Outlook (pdf is added as attachment), this is the part with Sleep 2000. After that it completes the email I need to send.

Now everything seems to work except:
When sending text ("Send text" lines) it skips one letter, for example writes "ext" or "txt".

Any ideas what else I could add to fix it? I actually thought Sleep time would fix it but it did not.
User avatar
Barney
Posts: 54
Joined: 28 May 2014, 20:03
Location: Germany

Re: Find and copy text from PDF to clipboard

01 Dec 2017, 08:04

try sending the clipboard with raw mode
Last edited by Barney on 01 Dec 2017, 12:12, edited 1 time in total.
Guest

Re: Find and copy text from PDF to clipboard

01 Dec 2017, 08:43

Try adding SendMode, input at the top your script or perhaps a SetKeyDelay (look it up).

Also note that by using capital F in Send F it also (probably) sends a SHIFT key, so it actually sends shift+f not just an f.
User avatar
Xtra
Posts: 2061
Joined: 02 Oct 2015, 12:15

Re: Find and copy text from PDF to clipboard

01 Dec 2017, 13:46

Paste the text using:

Code: Select all

Send, ^v
or

Code: Select all

Send, {Ctrl Down}v{Ctrl Up}
HTH

Return to “Ask For Help”

Who is online

Users browsing this forum: Arsonistic, Bing [Bot], Google [Bot], mikeyww, Out2lunch, paul1965 and 62 guests