Has someone tried to automate Acrobat Pro via COM before?
Are there snippets you would be willing to share?
I have found some information here
http://help.adobe.com/livedocs/acrobat_ ... index.html
But do not know really where to start and what I'm looking for to get the following done.
What I basically want to do is reduce the files size of PDFs: Open thousands of PDFs (in different folders) and save them with the PDF Optimizer replacing the original to reduce their size. Either directly (open/save as) or via the Action Wizard.
For the largest 11 files I have done this manually and it reduced the overall size from 248 MB to 86 MB. The 4310 PDF files I'm looking at use 4.35 GB in total.
Adobe Acrobat Pro via COM
Adobe Acrobat Pro via COM
ciao
toralf
toralf
- Blackholyman
- Posts: 1264
- Joined: 29 Sep 2013, 22:57
- Facebook: socialjsz
- Google: +Jszapp
- Location: Denmark
- Contact:
Re: Adobe Acrobat Pro via COM
I have not done much with adobe Acrobat pro
But did a little, a time back, and remember I got some good info from this link http://help.adobe.com/livedocs/acrobat_ ... sible=true
look for :
Example of opening and doing a simple save via COM:
But I did not have the time to go over all of the info in your link, but
Will tell you more about the structure you need to pass togetter with the AVDoc object if you find a way to invoke the AVDocSaveOptimized method
Hope it helps
But did a little, a time back, and remember I got some good info from this link http://help.adobe.com/livedocs/acrobat_ ... sible=true
look for :
- Acrobat Interapplication Communication
Necessary C knowledge
PDF Optimizer API
Example of opening and doing a simple save via COM:
Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus
App := ComObjCreate("AcroExch.App")
AVDoc := ComObjCreate("AcroExch.AVDoc")
; PVDoc := ComObjCreate("AcroExch.PDDoc")
; App.show()
FileSelectFile, path,,, Select a pdf, pdf (*.pdf)
AVDoc.Open(path, "")
SplitPath, path, OFN, OD, OE, ONNE, ODri
PVDoc := AVDoc.GetPDDoc()
PDSaveIncremental := 0x0000 ;/* write changes only */
PDSaveFull := 0x0001 ;/* write entire file */
PDSaveCopy := 0x0002 ;/* write copy w/o affecting current state */
PDSaveLinearized := 0x0004 ;/* write the file linearized for
PDSaveBinaryOK := 0x0010 ;/* OK to store binary in file */
PDSaveCollectGarbage := 0x0020 ;/* perform garbage collection on
PVDoc.save(PDSaveFull|PDSaveLinearized, OD . "\final.pdf")
PVDoc.close()
App.CloseAllDocs()
App.exit()
return
But I did not have the time to go over all of the info in your link, but
- AV_Layer
- AVDoc
- AVDocSaveParams
- _t_AVDocSaveParams
Will tell you more about the structure you need to pass togetter with the AVDoc object if you find a way to invoke the AVDocSaveOptimized method
Hope it helps
Re: Adobe Acrobat Pro via COM
Thank you so much.
That should be enough to get me started.
Edit:
In the IAC I did not find a way to start the Optimizer. Somehow I would need to invoke a different API.
void AVDocSaveOptimized(AVDoc avDoc, const PDFOptParamsRec* pdfOptParams)
For which I could get the Params with
ASBool AVGetOptimizerParamsForPreset(ASText presetName, AVDoc avDoc, PDFOptParams pdfOptParams)
But I have not figured out how to call this API with the COM commands.
I'll try if I can get a menu item to execute via the IAC, or even to automate Acrobat via keyboard shortcuts.
That should be enough to get me started.
Edit:
In the IAC I did not find a way to start the Optimizer. Somehow I would need to invoke a different API.
void AVDocSaveOptimized(AVDoc avDoc, const PDFOptParamsRec* pdfOptParams)
For which I could get the Params with
ASBool AVGetOptimizerParamsForPreset(ASText presetName, AVDoc avDoc, PDFOptParams pdfOptParams)
But I have not figured out how to call this API with the COM commands.
I'll try if I can get a menu item to execute via the IAC, or even to automate Acrobat via keyboard shortcuts.
ciao
toralf
toralf
Re: Adobe Acrobat Pro via COM
Has someone worked with Acrobat via DllCall?
I can load Acrobat.dll and AdobePDFL.dll but when I try to call a method (e.g. AVAppBeginFullScreen) I get an error level of -4 (The specified function could not be found inside the DLL)
In which DLL file do I find the functions of the API?
At the end I need to use the method AVDocSaveOptimized, but since it seems to be more difficult to set up the parameters I wanted to start 'easy'... I can't even get started. *Frust*
Edit: The Acrobat folder contains 295 Dlls....
I can load Acrobat.dll and AdobePDFL.dll but when I try to call a method (e.g. AVAppBeginFullScreen) I get an error level of -4 (The specified function could not be found inside the DLL)
In which DLL file do I find the functions of the API?
At the end I need to use the method AVDocSaveOptimized, but since it seems to be more difficult to set up the parameters I wanted to start 'easy'... I can't even get started. *Frust*
Edit: The Acrobat folder contains 295 Dlls....
ciao
toralf
toralf
- Blackholyman
- Posts: 1264
- Joined: 29 Sep 2013, 22:57
- Facebook: socialjsz
- Google: +Jszapp
- Location: Denmark
- Contact:
Re: Adobe Acrobat Pro via COM
can't say much
this may have something http://www.postseek.com/result/?query=a ... eoptimized

Re: Adobe Acrobat Pro via COM
It's not possible to call optimization from outside of acrobat
https://forums.adobe.com/thread/301716?start=12
Only via a plugin.
https://forums.adobe.com/thread/301716?start=12
Only via a plugin.
ciao
toralf
toralf
Re: Adobe Acrobat Pro via COM
This is what I came up with. Not nice, but it is working
Code: [Select all] [Expand] [Download] (Untitled.txt)GeSHi © Codebox Plus
;requires AHK 1.1.20+
;create a action with the Action Wizard to optimize a file
; - start with: "a file open in Acrobat"
; - no additional steps
; - save to: "The Same Folder Selected at Start"
; - Adjust save options: Check "PDF Optimizer"
; - check: "Overwrite existing files"
; - Save Action. Name doesn't matter, it must be the 3rd item in the menu
SetTitleMatchMode, 2
Gui, +AlwaysOnTop
Gui, Add, Text, ,Drop PDF files here to save optimized (overwrite!)
Gui, Show, , Reduce PDF File Size
Return
GuiClose:
BlockInput, Off
ExitApp
Return
GuiDropFiles(GuiHwnd, FileArray){
for i, file in FileArray{
App := ComObjCreate("AcroExch.App")
AVDoc := ComObjCreate("AcroExch.AVDoc")
AVDoc.Open(file, "")
PDDoc := AVDoc.GetPDDoc()
PDDoc.OpenAVDoc("Optimize")
WinWait, - Adobe Acrobat Pro, , 60
If ErrorLevel {
MsgBox, Could not detect Adobe Acrobat Pro
App.exit()
Continue
}
BlockInput, On
WinActivate
WinWaitActive
Send, , !fw{Down}{Down}{Enter} ;select the 3rd item in the actions menu
BlockInput, Off
WinWait, Optimize PDF File, Action Completed
BlockInput, On
WinActivate
WinWaitActive
Send, {Enter}
BlockInput, Off
PDDoc.close()
App.CloseAllDocs()
App.exit()
}
}
ciao
toralf
toralf
Re: Adobe Acrobat Pro via COM
Can these COM commands also be used to start things on the toolbar in Acrobat Pro for example to open the merge pdf window? Because Adobe has not added hotkeys to start many of the toolbar tools. Once the tool windows are open they are in many cases straightforward to control with send key commands.
Re: Adobe Acrobat Pro via COM
I'm getting back to this question after having searched more and tried a few things. But I've only figured out how to start the Acrobat application itself with COM but I can't find a method to open any of the toolbar tools through COM. ImageSearch for the toolbar icon is a possibility but that method is sensitive to changes in resolution and other settings on different computers. I guess Adobe wanted to make it hard to automate Acrobat and sell more of the super expensive corporate tools instead. 

- Blackholyman
- Posts: 1264
- Joined: 29 Sep 2013, 22:57
- Facebook: socialjsz
- Google: +Jszapp
- Location: Denmark
- Contact:
Re: Adobe Acrobat Pro via COM
@toopy
Don't need to use the toolbar buttons an example of how to combine two PDF documents and save the result as a new document
But if you wish to try and execute toolbar actions you can use MenuItemExecute() the hard part, in that, is that you need to know the name that adobe uses for the item you wish to execute
Example of showing the SaveAs dialog
Hope it helps
Don't need to use the toolbar buttons an example of how to combine two PDF documents and save the result as a new document
Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus
AcroApp := ComObjCreate("AcroExch.App")
Part1Document := ComObjCreate("AcroExch.PDDoc")
Part2Document := ComObjCreate("AcroExch.PDDoc")
Part1Document.Open(A_Desktop "\Part1.pdf")
Part2Document.Open(A_Desktop "\Part2.pdf")
; Insert the pages of Part2 after the end of Part1
numPages := Part1Document.GetNumPages()
If (Part1Document.InsertPages(numPages - 1, Part2Document, 0, Part2Document.GetNumPages(), -1) = False)
MsgBox Cannot insert pages
PDSaveFull = 1
;PDSaveBinaryOK = 16
;PDSaveCollectGarbage = 32
;PDSaveCopy = 2
;PDSaveIncremental = 0
;PDSaveLinearized = 4
;PDSaveWithPSHeader = 8
If (Part1Document.Save(PDSaveFull, A_Desktop "\MergedFile.pdf") = False)
MsgBox Cannot save the modified document
Part1Document.Close
Part2Document.Close
AcroApp.Exit
MsgBox "Done"
But if you wish to try and execute toolbar actions you can use MenuItemExecute() the hard part, in that, is that you need to know the name that adobe uses for the item you wish to execute
Example of showing the SaveAs dialog
Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus
oAcrobat := ComObjCreate("acroExch.App")
oAcrobatdoc := ComObjCreate("acroexch.avdoc") ; create an document object
oAcrobat.maximize(-1) ; maximize the application window (-1 = true)
oAcrobatdoc.Open(A_Desktop "\Part1.pdf", "")
oAcrobat.show() ; make the application object visible or .hide it
sleep 2000
oAcrobat.MenuItemExecute("SaveAs")
return
Hope it helps
- tank
- Posts: 2257
- Joined: 28 Sep 2013, 22:15
- Facebook: charlie.simmons.7334
- Google: ttnnkkrr
- GitHub: ttnnkkrr
- Location: Louisville KY
- Contact:
Re: Adobe Acrobat Pro via COM
Super that this is so current and relevant to a current project where combining pdf documents is going to be necessary
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Re: Adobe Acrobat Pro via COM
Thank you very much Blackholyman for that code snippet, it helped a lot.
Yes I'd also like to start the window for "Text recognition in multiple files" and "Text recognition in this file". Once the windows are open it is easy to automate then by sending keys. Any idea what the names for those command could be?
Blackholyman wrote:But if you wish to try and execute toolbar actions you can use MenuItemExecute() the hard part, in that, is that you need to know the name that adobe uses for the item you wish to execute
Yes I'd also like to start the window for "Text recognition in multiple files" and "Text recognition in this file". Once the windows are open it is easy to automate then by sending keys. Any idea what the names for those command could be?
- Blackholyman
- Posts: 1264
- Joined: 29 Sep 2013, 22:57
- Facebook: socialjsz
- Google: +Jszapp
- Location: Denmark
- Contact:
Re: Adobe Acrobat Pro via COM
@Tank
Absolutely
@toopy
Know of one you can try
Absolutely

@toopy
Know of one you can try
oAcrobat.MenuItemExecute("Cpt:CapturePages")
Re: Adobe Acrobat Pro via COM
Blackholyman wrote: Know of one you can tryoAcrobat.MenuItemExecute("Cpt:CapturePages")
Did not work in Acrobat XI Pro I'm afraid. I could be because there is no entry in the menu to start the "Text recognition in multiple files" and "Text recognition in this file" dialogs. Those can only be started from a toolbar icon or from the tools sidebar. Is there some command similar to MenuItemExecute to run stuff like that?
- Blackholyman
- Posts: 1264
- Joined: 29 Sep 2013, 22:57
- Facebook: socialjsz
- Google: +Jszapp
- Location: Denmark
- Contact:
Re: Adobe Acrobat Pro via COM
Not that I know of the top of my head sorry...
Re: Adobe Acrobat Pro via COM
Blackholyman wrote:Not that I know of the top of my head sorry...
I searched for som Acrobat SDK/API/etc documentation of what commands are available but came up empty. Does anyone have a full list of commands? Another possibility I've thought about is doing PostMessage type of commands but I'm not sure if that would work with Acrobat. What is the currently best tool to spy what such messages an application uses?
Who is online
Users browsing this forum: cl_panda, djclinton18 and 50 guests