Jump to content
Sign in to follow this  
xolomon

Acrobat Reader Operations in the Background

Recommended Posts

xolomon

Dear all,

I am using the Autoit to encrypt PDF files. I would like to open several pdf files one by one, encrypt them and save in another folder. I would like to limit the user actions during these operations. I have tried the method,

BlockInput(1)

but in this case, I cannot access to the acrobat reader menu by sending commands as the inputs are blocked. What can be an alternative in this case either to avoid user interaction or run this process in background? Can you provide me examples? Here is my code that basically opens a pdf file and saves in another folder.

O.S. : Windows XP Professional X64

Adobe Acrobat Reader X 10.0 Professional

Autoit: 3.3.8.0

#cs
Define Environment
#ce
;Debugingmodus wird aktiviert
AutoItSetOption("TrayIconDebug",1)
$acrobatPfad= "C:\Program Files\\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe"

$d = 500 ;Delay between commands
$filepath = "Z:\2013\01_PDF_Schutz\Testdaten"
$file = "262000_____0000.pdf"
$fileopen = $filepath & "\" & $file
#cs
Start Acrobat Reader with file
#ce
$title = $file & " - Adobe Reader"
$handle = WinGetHandle("[CLASS:AcrobatSDIWindow]", "")
Run($acrobatPfad & " " & $fileopen)
sleep($d)
WinWaitActive($title)
Sleep($d)
Send("{ALT}")
Sleep($d)
Send("{DOWN}")
Sleep($d)
Send("{DOWN}")
Sleep($d)
Send("{DOWN}")
Sleep($d)
Send("{ENTER}")
Sleep($d)
Send($file & "_active.pdf")
Sleep($d)
Send("{ENTER}")
Sleep($d)
ProcessClose("AutoIt3.exe")

Share this post


Link to post
Share on other sites
water

A few remarks.

  • Please wrap your script in [autoit][/autoit] tags. Enhances readability!
  • Don't use Send use Control* functions
  • Don't use Sleep after the run statement. Wait for the Window to pop up (WinWait)
  • Remove ProcessClose. "Exit" is enough.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
xolomon

Dear Water,

thank you for your remarks. I have updated my code depending on your remarks as follows:

#cs
Define Environment
#ce
;Debugingmodus wird aktiviert

AutoItSetOption("TrayIconDebug",1)
 
$acrobatPfad = "C:\Program Files\\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe"

Opt("SendKeyDelay", 500) ;5 milliseconds

$filepath = "Z:\01_PDF_Schutz\Testdaten"
$file = "62000_____0000.pdf"
$fileopen = $filepath & "\" & $file

BlockInput(1)

#cs
Start Acrobat Reader X with file
#ce

$title = $file & " - Adobe Reader"
$handle = WinGetHandle("[CLASS:AcrobatSDIWindow]", "")

Run($acrobatPfad & " " & $fileopen)
WinWaitActive($title)


ControlSend($title,"","","{ALT}")
ControlSend($title,"","","{DOWN 3}")
ControlSend("[CLASS:AcrobatSDIWindow]","","","{ENTER}")
ControlSetText("[CLASS:AcrobatSDIWindow]","","",$file & "_active.pdf")
ControlSend("[CLASS:AcrobatSDIWindow]","","","{ENTER}")

BlockInput(0)

 
Exit

I have the problem that when I use the blockinput, the commands that I sent to acrobat reader starting with "alt" command are not any more executed. Without blockinput works correctly. What can be the problem in this case? (I use windows xp professional sp2)

Share this post


Link to post
Share on other sites
water

Try to remove BlockInput. Shouldn't be necessary any more. Only Send statements can interfere with user input.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
xolomon

Dear Water,

I want to avoid the user interruption during the script execution. I have thought two possibilities, one to use block input and the second to start the acrobat reader either in minimized version or hide it as here.

Run($acrobatPfad & " " & $fileopen, @SW_HIDE)

The block input function didn't worked correctly, after sending the "alt" command it is stoped. While running in "hide" mode, I didn't get any reaction after running the script. What would you recommend in this case?

Share this post


Link to post
Share on other sites
water

Which command (encrypt PDF files) do you try to automate? I can't find anything about encryption?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
xolomon

I am doing the encryption (setting password) using the menu operations of the Acrobat Reader. I start the acrobat reader and select the related menu where you can setup a password and then save the file.  

Share this post


Link to post
Share on other sites
BrewManNH

Where in Reader are you able to set a password? Are you sure you don't need Adobe Acrobat for that? Reader is just for reading PDFs.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
xolomon

I am using Adobe Acrobat X Professional. 

Share this post


Link to post
Share on other sites
BrewManNH

Well, your script is looking for the Reader window, not the Acrobat window, which is probably most of the issue you're having.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JLogan3o13

Not to mention you have several times stated you were trying to do this in Acrobat reader. Not exactly helping us help you :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
xolomon

Sorry for the misunderstanding, but the problem is that I am using at work acrobat reader professional and at home acrobat reader. That is the reason for the confusion :ermm:. Thanks for your help.  

Share this post


Link to post
Share on other sites
JLogan3o13

As has been pointed out though, Acrobat Reader cannot do what Acrobat can - so your script is never going to work the same in both places. Are you trying to encrypt them at work, and then open them and input the password at home?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
xolomon

I am working on setting the keyword at work with the professional version. For me the problem is to perform acrobat menu actions while acrobat is running in either hidden or minized mode. For this reason I try with acrobat reader more basic operations like opening a file and saving it to a location with another name. Currently I am trying to use the "WinMenuSelectItem" function to send file open command to the acrobat reader and couldn't manage. What can be the reason for that? (I tried with acrobat reader 9)

Run($acrobatPath)
WinWait("Acrobat Reader")
WinMenuSelectItem("Acrobat Reader", "", "&File", "&Open...")

Share this post


Link to post
Share on other sites
BrewManNH

I don't believe that Reader menus will work with that command, you might try doing a ControlSend to the window with the shortcut key that Reader/Acrobat uses. I did this to fire off the File/Open menu item.

ControlSend("Adobe Reader", "", "", "^o")

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
xolomon

Yes, using the control send there is no problem, thanks. I have another question, when I start the acrobat reader in the hidden or minimized mode and send the file open command, acrobat reader becomes visible with the "Open" window activated. I have tried to hide the open file window but it doesn't work.

WinWait("[TITLE:Öffnen]", "", 10)

WinSetState("[TITLE:Öffnen]", "",  @SW_HIDE)

Share this post


Link to post
Share on other sites
jdelaney

Unfortunatly the menu items can only be grabbed on the first level (file, help, etc)...the menu's under them hide all information.  I was playing around with the _GuiCtrlMenu functions...

$hwnd = WinGetHandle("[CLASS:AcrobatSDIWindow]")
WinActivate($hwnd)
$hMenu = _GUICtrlMenu_GetMenu($hwnd)
$iFile = _GUICtrlMenu_FindItem($hMenu, "File")
$hFileMenu = _GUICtrlMenu_GetItemSubMenu($hMenu, $iFile)
For $i = 0 To _GUICtrlMenu_GetItemCount($hMenu) - 1
    ConsoleWrite(_GUICtrlMenu_GetItemText($hMenu,$i) & " " & @error & @CRLF)
Next

ConsoleWrite($hFileMenu & @CRLF)
For $i = 0 To _GUICtrlMenu_GetItemCount($hFileMenu) - 1
    ConsoleWrite(_GUICtrlMenu_GetItemText($hFileMenu,$i, True) & " " & @error & @CRLF)
Next

output:

&File 0
&Edit 0
&View 0
&Window 0
&Help 0
 0
0x0F760E03
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×