WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Automation of Adobe Acrobat Exchange

Keywords: 	 adobe acrobat exchange

Question:

Here is a little utility I wrote to help with the automation of Adobe Acrobat Exchange – it may be easily modified to work with any other Windows program so don't be put off. I wrote it because Acrobat Exchange has no in-built macro or batch processing facility and I needed to cut down the number of repetitive keystrokes required to process some 7,000 PDF files!

The program illustrates a number of ideas and some good programming practice for those new to WinBatch:

I like to use INI files to hold program options for three reasons:

  1. The script behaviour may be modified by changing the INI file without need to modify the WinBatch code – good for users who know nothing about WinBatch especially if users have compiled scripts.
  2. Options set by the user as the script runs can be saved and restored the next time the script is run.
  3. INI files are a safer bet than playing about with your own Registry entries and can also be edited quickly and easily by Notepad or Winbatch Studio.
I create an INI file in the directory obtained by DirHome() so I always know that the INI file is in the same directory as the compiled script. The X and Y coordinates of the dialog are read from the INI file (so these may be customised) but in this application, they are set to 1,1 as default values since I want the dialog to be in the top left-hand corner of the screen away from the other application window unless overridden by the values stored in the INI file. I give the user the choice of font to be used in the dialog box (proportional or system font) and use IntControl(52,,,,) to set this – this may be changed as the script runs by the user clicking the Options... button (the value is stored in the INI file). I define variables at the top of the script to hold the name of the windows I will be using with WinExist and SendKeysTo – this way, the program can be easily amended to work with other applications by changing 1 or 2 lines rather than looking for every occurrence of WinExist and SendKeysTo in the whole script. I test to see if the target application exists before I attempt to send keystrokes to it. I use IntControl(35,0,0,0,0) to send all keystrokes as fast as possible – NB you may want to comment this out or set a delay greater than the default if your application can't keep up. I separate out the dialog set up statements as a subroutine and call them only as needed. To activate the dialog, I simply use the Dialog("dialogname") command to activate the dialog – there is no point in re-executing the same code needlessly. NB In this script, the dialog setup statements are called again if the Options... menu is accessed since the dialog size and button size may need re-adjusting.

I use a switch/case construction to direct the processing after a button has been clicked and loop round to the start to re-display the dialog after the appropriate actions have been taken after a button click. Where the target application requires text input, this is requested by the WinBatch script as an AskLine() statement and then passed to the target application since it is difficult to give the target window the focus while the script is running. There is no case condition for the Exit button, since WinBatch will always terminate when a button with a value of 0 is pressed (unless, of course, you have a :cancel label in your script which would be useful if you had some tidying up to do before actually exiting the script).

A Mk2 version of this will allow the target application, window names, button labels and keystrokes to be defined externally in the INI file so it becomes more general-purpose. Also, the Options... dialog will be greatly extended to allow the INI file to populated easily.

I hope this script proves useful to somebody.

David R Stout

Answer:

;--------------------------------------------------------------------------------------
; Acrobat Macros by David R Stout, August 1998
;--------------------------------------------------------------------------------------

revision    = "1.1"
CurrentDir  = DirHome()
IniFile     = "%CurrentDir%AcroKeys.ini"
AcroDialogX = IniReadPvt("Options","Xpos","1",IniFile)
AcroDialogY = IniReadPvt("Options","Ypos","1",IniFile)
FontStyle   = IniReadPvt("Options","FontStyle","1",IniFile)
TargetWin	= "Acrobat Exchange"
LinkWin     = "Create Link"

if WinExist(TargetWin) == @False then
	Message("AcroKeys Error","Cannot find Acrobat Exchange window. Program terminating now")
	Exit
end if

IntControl(35,0,0,0,0)

gosub ScaleDialogBox

:start

Button1 = Dialog("AcroDialog")
switch Button1

	case 1 ; Open
		SendKeysTo(TargetWin,'^o')
		break
	case 2 ; Magnification Set
		SendKeysTo(TargetWin,'!da!ag!mffff~~')
		break
	case 3 ; Text Outline
		SendMenusTo(TargetWin,"Tools TouchUp Text")
		break
	case 4 ; Text Colour
		SendKeysChild(TargetWin,'','!ex')
		break
	case 5 ; Hyperlink Outline
		SendKeysTo(TargetWin,'!tl')
		break
	case 6 ; Hyperlink Assign
		if WinExist(LinkWin) then
			URL = AskLine('Hyperlink Assign','Enter name of PDF file to link to','.pdf')
			SendKeysTo(LinkWin,'!yi!tw!u')
			SendKeysTo(LinkWin,URL)
			SendKeysTo(LinkWin,'~~')
		else
			Message('Error','Create HyperLink Outline first !')
		end if
		break
	case 7 ; Save and Close
		SendKeysTo(TargetWin,'^s^w')
		break
	case 8 ; Options
		FontStyle = FontStyle + 1
		Button2   = Dialog("Options")
		FontStyle = FontStyle - 1
		IniWritePvt("Options","FontStyle", FontStyle, IniFile)
		gosub ScaleDialogBox
		break

end switch

goto start

exit

;--------------------------------------------------------------------------------------
:ScaleDialogBox

if FontStyle == 0 then
	AcroDialogWidth  =  73
	AcroDialogHeight = 131
	ButtonSize       =  66
	OptionsWidth     = 103
	Offset           =  16
else
	AcroDialogWidth  =  53
	AcroDialogHeight = 132
	ButtonSize       =  46
	OptionsWidth     =  83
	Offset           =   7
end if
gosub AcroDialog
gosub OptionsDialog
IntControl(52,FontStyle,0,0,0)

return

;--------------------------------------------------------------------------------------
:AcroDialog

AcroDialogFormat=`WWWDLGED,5.0`

AcroDialogCaption=`Acrobat Keys %revision%`
AcroDialogNumControls=9

AcroDialog01=`2,2,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"Open PDF &File",1`
AcroDialog02=`2,16,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"&Magnification Set",2`
AcroDialog03=`2,30,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"&Text Outline",3`
AcroDialog04=`2,44,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"Text &Colour",4`
AcroDialog05=`2,58,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"&Hyperlink Outline",5`
AcroDialog06=`2,72,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"Hyperlink &Assign",6`
AcroDialog07=`2,86,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"&Save and Close",7`
AcroDialog08=`2,100,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"&Options...",8`
AcroDialog09=`2,114,%ButtonSize%,DEFAULT,PUSHBUTTON,DEFAULT,"E&xit",0`

return

;--------------------------------------------------------------------------------------
:OptionsDialog

OptionsFormat=`WWWDLGED,5.0`

OptionsCaption=`Options`
OptionsX=-1
OptionsY=-1
OptionsHeight=64
OptionsNumControls=4

Options01=`%Offset%,44,64,DEFAULT,PUSHBUTTON,DEFAULT,"&OK",1`
Options02=`4,4,100,DEFAULT,STATICTEXT,DEFAULT,"Font Style"`
Options03=`8,16,100,DEFAULT,RADIOBUTTON,FontStyle,"&Proportional Font (small)",2`
Options04=`8,28,100,DEFAULT,RADIOBUTTON,FontStyle,"&System Font (large)",1`

return

;--------------------------------------------------------------------------------------

Article ID:   W13767
Filename:   Automation of Adobe Acrobat Exchange.txt
File Created: 2001:01:08:12:16:36
Last Updated: 2001:01:08:12:16:36