Adobe Acrobat Pro via COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Adobe Acrobat Pro via COM

09 Mar 2015, 13:13

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.
ciao
toralf
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Adobe Acrobat Pro via COM

09 Mar 2015, 19:30

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 :
  • Acrobat Interapplication Communication
    Necessary C knowledge
    PDF Optimizer API
Example of opening and doing a simple save via COM:

Code: Select all

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
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Adobe Acrobat Pro via COM

09 Mar 2015, 20:07

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.
ciao
toralf
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Adobe Acrobat Pro via COM

10 Mar 2015, 14:54

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....
ciao
toralf
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Adobe Acrobat Pro via COM

10 Mar 2015, 19:58

It's not possible to call optimization from outside of acrobat
https://forums.adobe.com/thread/301716?start=12

Only via a plugin.
ciao
toralf
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Adobe Acrobat Pro via COM

11 Mar 2015, 07:38

This is what I came up with. Not nice, but it is working

Code: Select all

;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
toopy

Re: Adobe Acrobat Pro via COM

05 Sep 2015, 13:46

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.
toopy

Re: Adobe Acrobat Pro via COM

20 Sep 2015, 11:38

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. :(
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Adobe Acrobat Pro via COM

20 Sep 2015, 13:46

@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

Code: Select all

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

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
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Adobe Acrobat Pro via COM

20 Sep 2015, 13:59

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;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
toopy

Re: Adobe Acrobat Pro via COM

20 Sep 2015, 16:52

Thank you very much Blackholyman for that code snippet, it helped a lot.
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?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Adobe Acrobat Pro via COM

20 Sep 2015, 17:22

@Tank
Absolutely :)

@toopy
Know of one you can try oAcrobat.MenuItemExecute("Cpt:CapturePages")
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
toopy

Re: Adobe Acrobat Pro via COM

21 Sep 2015, 03:54

Blackholyman wrote: Know of one you can try oAcrobat.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?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Adobe Acrobat Pro via COM

21 Sep 2015, 03:58

Not that I know of the top of my head sorry...
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
toopy

Re: Adobe Acrobat Pro via COM

25 Sep 2015, 06:07

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?
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Adobe Acrobat Pro via COM

12 Jun 2018, 12:42

http://www.planetpdf.com/forumarchive/40476.asp --> I Found this link with a bunch of them, but I cannot prove that they work.

Still on the topic, I had a question about the https://help.adobe.com/en_US/acrobat/ac ... rhsyns=%20
I have tried to make a com object but for some reason I keep coming up with that it doesn't know the command.


Original by Blackholyman

Code: Select all

oAcrobat := ComObjCreate("acroExch.App")
oAcrobatdoc := ComObjCreate("acroExch.avdoc")      ; create an document object
;oAcrobat.maximize(1)      ; maximize the application window (-1 = true)

oAcrobatdoc.Open(A_ScriptDir "\FileToRead.pdf", "")

oAcrobat.hide() ; make the application object visible or .hide it
;oAcrobat.MenuItemExecute("SaveAs")
oAcrobat.saveAs(A_ScriptDir "FileToRead.xml", "com.adobe.acrobat.xml-1-00")
oAcrobat.MenuItemExecute("Close")
Any thoughts?
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Adobe Acrobat Pro via COM

12 Jun 2018, 16:30

toopy wrote:
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?
Here is an example for MenuItemExecute that I use often.

Code: Select all

App := ComObjCreate("AcroExch.App")
App.Show()
App.MenuItemExecute("ImageConversion:Clipboard")
App.MenuItemExecute("SaveAs")
It converts an image on the clipboard to a PDF and then opens a SaveAs dialog to save the new PDF.

Here is a list of menu commands:

Code: Select all

/*
[cName:File, oChildren:[[cName:Open],[cName:endOpenGroup],[cName:NewDocument, oChildren:[[cName:NewDocFromFile],[cName:ScanMenu, oChildren:[[cName:ScanPreset5],[cName:ScanPreset1],[cName:ScanPreset2],[cName:ScanPreset3],[cName:ScanPreset4],[cName:],[cName:Scan],[cName:],[cName:ScanConfigurePreset]]],[cName:Web2PDF:OpnURL],[cName:ImageConversion:Clipboard],[cName:],[cName:NewDocCombineFiles],[cName:CreateMultiplePDFFiles],[cName:],[cName:AcroForm:Forms_CreateNewForm],[cName:endCreatePDFGroup],[cName:NewDocCreateCollection]]],[cName:],[cName:Save],[cName:SaveAs],[cName:SaveAsSubmenu, oChildren:[[cName:ReduceFileSize],[cName:DIGSIG:SaveAndAuthenticate],[cName:SaveAsExtendedSubmenu, oChildren:[[cName:DIGSIG:UBDoc]]],[cName:PDFOptimizer]]],[cName:endSaveGroup],[cName:Email],[cName:SPAObject 50],[cName:SPAObject 51],[cName:],[cName:],[cName:],[cName:Revert],[cName:Close],[cName:endFormDataGroup],[cName:GeneralInfo],[cName:endDocInfoGroup],[cName:Print],[cName:endPrintGroup],[cName:SPAObject 46],[cName:SPAObject 47],[cName:RecentFile1],[cName:endRecentFileGroup],[cName:Quit]]],[cName:Edit, oChildren:[[cName:Undo],[cName:Redo],[cName:endUndoGroup],[cName:Cut],[cName:Copy],[cName:Paste],[cName:Clear],[cName:endEditGroup],[cName:SelectAll],[cName:DeselectAll],[cName:endSelectGroup],[cName:CopyFileToClipboard],[cName:endOleGroup],[cName:TouchUp:EditDocument],[cName:],[cName:SelectGraphics],[cName:],[cName:Spelling:Spelling, oChildren:[[cName:Spelling:Check Spelling],[cName:Spelling:Edit Dictionary]]],[cName:LookUpWord],[cName:endLookUpGroup],[cName:Find],[cName:FindSearch],[cName:endFindGroup],[cName:GeneralPrefs]]],[cName:View, oChildren:[[cName:Rotate, oChildren:[[cName:RotateCW],[cName:RotateCCW]]],[cName:GoTo, oChildren:[[cName:FirstPage],[cName:PrevPage],[cName:NextPage],[cName:LastPage],[cName:GoToPage],[cName:endPageNavGroup],[cName:GoBack],[cName:GoForward]]],[cName:],[cName:PageLayout, oChildren:[[cName:SinglePage],[cName:OneColumn],[cName:TwoPages],[cName:TwoColumns],[cName:endPageLayoutSubGroup],[cName:ShowGaps],[cName:ShowCoverPage],[cName:],[cName:AutoScroll]]],[cName:ZoomSubMenu, oChildren:[[cName:ZoomTo],[cName:Zoom],[cName:ZoomDrag],[cName:],[cName:ActualSize],[cName:FitPage],[cName:FitWidth],[cName:FitHeight],[cName:FitVisible],[cName:endFitGroup],[cName:PanZoom],[cName:Loupe],[cName:],[cName:Reflow]]],[cName:endGoToGroup],[cName:TaskPanesSectionStart],[cName:ShowHideSubMenu, oChildren:[[cName:Navigation, oChildren:[[cName:ShowHideAccessibilityCheck],[cName:ShowHideAccessibilityReport],[cName:ShowHideArticles],[cName:ShowHideFileAttachment],[cName:ShowHideBookmarks],[cName:ShowHideContentPanel],[cName:ShowHideDestinations],[cName:ShowHideOptCont],[cName:ShowHideModelTree],[cName:ShowHideOrderPanel],[cName:ShowHideThumbnails],[cName:ShowHideRecognitionReport],[cName:ShowHideRemoveHiddenInfo],[cName:ShowHideWorkflowPanel],[cName:ShowHideSignatures],[cName:ShowHidePDFStandards],[cName:ShowHideTagsPanel],[cName:endShowHideWindowsGroup2],[cName:ShowHideNavigationPane],[cName:ResetPanels],[cName:]]],[cName:HoldoverToolbars],[cName:ShowHideMenuBar],[cName:],[cName:RulersAndGridsGroup, oChildren:[[cName:ShowGrid],[cName:SnapToGrid],[cName:ShowRulers],[cName:ShowGuides],[cName:Wireframe]]],[cName:ShowInfo]]],[cName:],[cName:ReadingMode],[cName:FullScreenMode],[cName:endFullScreenGroup],[cName:Annots:ReviewTracker],[cName:],[cName:ReadAloud, oChildren:[[cName:ADBE:ReadOutLoudOnOff],[cName:ADBE:ReadAloudStart],[cName:ADBE:ReadAloudToEnd],[cName:ADBE:ReadAloudPauseResume],[cName:ADBE:ReadAloudStop]]],[cName:DIGSIG:CompareDocuments]]],[cName:Window, oChildren:[[cName:NewWindow],[cName:],[cName:Cascade],[cName:Tile, oChildren:[[cName:TileHorizontal],[cName:TileVertical]]],[cName:MinimizeAll],[cName:endWindowLayoutGroup],[cName:SplitWindow],[cName:SpreadsheetSplit]]],[cName:Help, oChildren:[[cName:HelpUserGuide],[cName:endGuideGroup],[cName:About],[cName:AboutAdobeExtensions],[cName:endAboutPlugInGroup],[cName:UsageMeasurement],[cName:],[cName:AMTDynamic1],[cName:AMTDynamic2],[cName:startEBookServicesGroup],[cName:eBook:Digital Edition Services],[cName:endEBookServicesGroup],[cName:OnlineSupport, oChildren:[[cName:KnowledgeBase],[cName:AdobeExpertSupport],[cName:AdobeUserCommunity],[cName:AccessOnline],[cName:],[cName:SystemInformation]]],[cName:DetectAndRepair],[cName:Updates]]]
*/
At a glance I see a ReduceFileSize and PDFOptimizer in there.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Adobe Acrobat Pro via COM

12 Jun 2018, 16:46

MannyKSoSo wrote:I have tried to make a com object but for some reason I keep coming up with that it doesn't know the command.
Just realized this is an old thread.

There are alot of different kinds of COM objects associated with Acrobat. What ComObjCreate command are you trying that fails?

Also, just to be clear to work with Acrobat through COM, you need the paid version of Acrobat. The Reader and free versions don't support COM.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Adobe Acrobat Pro via COM

12 Jun 2018, 16:56

Specifically it has to do with the saveAs part of the code

Code: Select all

oAcrobat.saveAs(A_ScriptDir "FileToRead.xml", "com.adobe.acrobat.xml-1-00")
The documentation is a little confusing to me on the subject (just because I am still learning all the commands). Also I do indeed have the paid version of Acrobat.

To give a better example of what is happening is that after I read and open the file through the com I try and convert it to an xml file (which works fine if you use the part of the code that is commented out) but I was trying to make it use the built in saveAs. When that specific part of the code runs, it doesn't recognize the action. Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, RussF, TheDewd and 136 guests