2

I'm trying to make a program to open Acrobat files using Adobe Acrobat Reader and save them in a text file, automatically. What I want my program to do is:

  • open the pdf
  • send Alt + Tab //to move to the acrobat tab
  • send Alt + F //to open file
  • send Down Down Down Down (4 times) //to select 'save as text' option
  • send Enter // to save

I'm using Windows OS. can someone please help me on how to do this?

Well my finel goal is to save the title and author of about 2500 pdf files in a database automatically, what are the better ways you suggested ? this was what i came up with.

Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
SNBR
  • 33
  • 1
  • 8
  • 2
    There are better (read: faster) options than opening Acrobat Reader, is there a reason you picked this solution? – Stefan Mai Oct 10 '10 at 06:09
  • 1
    I recommend using OLE Automation instead, from a scripting language such as VBScript or JScript (they're bundled with Windows). Alternatively, if you're going to send keystrokes, but that's *fragile*, also that is easier from a scripting language. The Windows WScript family of automation objects provide keystroke sending functionality somewhere. Yes, anyway it involves googling or reading docs. :-) Adobe's Automation API is documented by Adobe, Windows' WScript object & friends is documented in MSDN Library. – Cheers and hth. - Alf Oct 10 '10 at 06:13
  • I agree with others that say this is a bad idea. There are better ways to do this... – Sasha Chedygov Oct 10 '10 at 07:06
  • Well my finel goal is to save the title and author of about 2500 pdf files in a database automatically, what are the better ways you suggested ? – SNBR Oct 11 '10 at 01:20

4 Answers4

0

You're going to want to use Spy++ and watch the messages being passed to the window when you perform these actions (note that opening the PDF with Acrobat and grabbing the Window handle are different operations). From there, look into:

http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx

Win32 messaging is difficult if you're not used to it and fragile, as mentioned by @Alf. I'd suggest you try another approach, but if you Google "win32 sendmessage" or "win32 sendkeys" that should get you started.

Stefan Mai
  • 23,367
  • 6
  • 55
  • 61
0

Couple of things,

1) Simulating keystrokes to interact with another application is a very very bad idea. You're better off finding API's that'll do the same thing.

If you still haven't changed your mind, read further...

2) For Saving, Why not use Ctrl+S to save, Ctrl+O to open. I'm Sure you'll find direct shortcuts for the others too.

Here's a Project that might help.

st0le
  • 33,375
  • 8
  • 89
  • 89
0

Try AutoIt. From it's website:

"AutoIt is a freeware Windows automation language. It can be used to script most simple Windows-based tasks."

Paul
  • 6,435
  • 4
  • 34
  • 45
  • but still having a problem, well i can get autoit to run notepad by giving Run("notepad.exe") like that i tried to get Run("acroRD32.exe") but it doesnt work, any idea why ? – SNBR Oct 13 '10 at 14:31
  • It's probably not in your path. Did you try putting the complete path in there? For example: Run("C:/Program Files/Adobe/acroRD32.exe") – Paul Oct 13 '10 at 19:54
0

You can use SendMessage API to send mouse and keyboard messages to a window, or you can use sendinput which simulates actual hardware events. I will agree with another person, use AutoIT

Raindog
  • 1,468
  • 3
  • 14
  • 28