Adobe Acrobat Pro via COM

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Adobe Acrobat Pro via COM

Re: Adobe Acrobat Pro via COM

Post by burque505 » 13 Jun 2018, 18:08

Thanks, FG, once again, for this super-helpful stuff.
Regards,
burque505

Re: Adobe Acrobat Pro via COM

Post by FanaticGuru » 13 Jun 2018, 13:43

An even more streamline version.

Code: [Select all]GeSHi © Codebox Plus

PDDoc := ComObjCreate("acroExch.PDDoc")      ; create an PD document object
PDDoc.Open(A_Desktop "\Test\Test.pdf") ; open a pdf into the PDDoc
JSO := PDDoc.GetJSObject ; this JavaScript object is mainly used by Acrobat to run its scripts engine
JSO.SaveAs(A_Desktop "\Test\TestXML.xml", "com.adobe.acrobat.xml-1-00") ; convert and save as xml
If you never intend to actually view the PDF then there is no need to create a AVDoc.

Also because there is not really any such thing as a hidden and visible PDDoc (they are never visible by nature), the PDDoc object is automatically destroyed when the AHK script ends and the AHK object is destroyed. If you were using this in some script that is not ending like this example, you can implicatively close the PDDoc with PDDoc.Close().

FG

Re: Adobe Acrobat Pro via COM

Post by FanaticGuru » 13 Jun 2018, 13:20

burque505 wrote:Kudos again to FG, as usual :) Manny, did your final code look anything like this?

Code: [Select all]GeSHi © Codebox Plus

App := 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", "")
sleep, 1500
AVDoc := App.GetActiveDoc()
PDDoc := AVDoc.GetPDDoc()
JSO := PDDoc.GetJSObject
JSO.SaveAs(A_ScriptDir "\FileToReadAsXML.xml", "com.adobe.acrobat.xml-1-00")

I can see where this would be really useful. One thing that comes to mind is extracting data from the PDF, and then using DocumentAssembler from OpenXmlPowerTools to populate a word document with that XML data.
Regards,
burque505

Here is a little more streamlined version (with some comments):

Code: [Select all]GeSHi © Codebox Plus

AVDoc := ComObjCreate("acroExch.AVDoc")      ; create an AV document object
AVDoc.Open(A_Desktop "\Test\Test.pdf", "") ; open a pdf into the AVDoc (this is a view but it is hidden by default)
PDDoc := AVDoc.GetPDDoc() ; get the underlining PDDoc of the AVDoc (this is kind of like the HTML of a webpage before it is processed and rendered)
JSO := PDDoc.GetJSObject ; this JavaScript object is mainly used by Acrobat to run its scripts engine
JSO.SaveAs(A_Desktop "\Test\TestXML.xml", "com.adobe.acrobat.xml-1-00") ; convert and save as xml
AVDoc.Close(1) ; otherwise there will be a hidden document still running in processes
Acrobat has various different and separate COM objects with separate methods. Everything is not organized under one application object like with Excel or other Microsoft products.

The main ones are App (application), AVDoc (Acrobat View), and PDDoc (Portable Document). There are others. Each can be created directly with ComObjCreate or spawned from each other. You don't always need all of them.

FG

Re: Adobe Acrobat Pro via COM

Post by burque505 » 13 Jun 2018, 12:05

Kudos again to FG, as usual :) Manny, did your final code look anything like this?

Code: [Select all]GeSHi © Codebox Plus

App := 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", "")
sleep, 1500
AVDoc := App.GetActiveDoc()
PDDoc := AVDoc.GetPDDoc()
JSO := PDDoc.GetJSObject
JSO.SaveAs(A_ScriptDir "\FileToReadAsXML.xml", "com.adobe.acrobat.xml-1-00")

I can see where this would be really useful. One thing that comes to mind is extracting data from the PDF, and then using DocumentAssembler from OpenXmlPowerTools to populate a word document with that XML data.
Regards,
burque505

Re: Adobe Acrobat Pro via COM

Post by MannyKSoSo » 13 Jun 2018, 07:01

Thanks FG, I indeed tested the code this morning and it works as I intended it too. I had also tested with just the PDDoc := AVDoc.GetPDDoc() part to see if it would work (but seems I was more off than I thought LOL).
burque505, I indeed tried to do something similar to what you had, but when you run the MenuItemExecute part of the code, it stops because it waits for you to input a name and type of document (which is why I changed my approach to the one FG provided).

Re: Adobe Acrobat Pro via COM

Post by burque505 » 12 Jun 2018, 20:18

:bravo:
Thanks, FG, fine advice as always.
regards,
burque505

EDIT: I had worked out this solution that requires two scripts. It works, but there must be a better way using COM. The problem I'm trying to overcome is the line

Code: [Select all]GeSHi © Codebox Plus

oAcrobat.MenuItemExecute("SaveAs")	

which is modal, I guess, and stops the script dead in its tracks. The other problem, of course, is that it's visible.

Script 1: acro.ahk
Spoiler


Script 1 runs Script 2, acrohelper.ahk:
Spoiler


EDIT: I changed both scripts just a little. This DOES work, but both scripts have to be in the same directory, and you have to run acro.ahk first, as it starts the second script. (I've tried using SetTimer to combine this into one script, but I haven't been able to kill Acrobat after the XML file is saved, although it does successfully save the XML file.)

Re: Adobe Acrobat Pro via COM

Post by FanaticGuru » 12 Jun 2018, 18:21

burque505 wrote:I'm not sure if the JS object for Acrobat takes the same arguments as the AHK Com object, but the code you provided:

Code: [Select all]GeSHi © Codebox Plus

oAcrobat.saveAs(A_ScriptDir "FileToRead.xml", "com.adobe.acrobat.xml-1-00")

appears to be for JavaScript, which Acrobat of course can use extensively.
Oh, I see now. I was a little confused. There is a DDE command SaveAs which was what I, at a glance, though you were trying to do.

Here is a tested JavaScript solution that works for me.

Code: [Select all]GeSHi © Codebox Plus

App := ComObjCreate("AcroExch.App")
AVDoc := App.GetActiveDoc()
PDDoc := AVDoc.GetPDDoc()
JSO := PDDoc.GetJSObject
JSO.SaveAs(A_Desktop "\Test\TestXML.xml", "com.adobe.acrobat.xml-1-00")
This uses AHK to create a COM object for Acrobat. Then uses Acrobat to create a JavaScript object that can execute the Javascript version of SaveAs to save the active document as XML.

You can look up alot of other file formats and SaveAs lots of different formats.

FG

Re: Adobe Acrobat Pro via COM

Post by FanaticGuru » 12 Jun 2018, 17:45

MannyKSoSo wrote:Specifically it has to do with the saveAs part of the code

Code: [Select all]GeSHi © Codebox Plus

oAcrobat.saveAs(A_ScriptDir "FileToRead.xml", "com.adobe.acrobat.xml-1-00")

At a quick glance without looking at any of your other code, you have to have a "\" between your path and filename.
oAcrobat.saveAs(A_ScriptDir "\FileToRead.xml", "com.adobe.acrobat.xml-1-00")
But there appears to be more going wrong than that. You have to have two full valid paths.

Code: [Select all] [Expand]GeSHi © Codebox Plus



Maybe something like this:

Code: [Select all]GeSHi © Codebox Plus

App := ComObjCreate("AcroExch.App")
App.DocSaveAs("C:\Test.pdf", "C:\Text.xml")
I don't know if that will work but it is looking like something closer to what would work based on just looking at the API Reference.

FG

Re: Adobe Acrobat Pro via COM

Post by burque505 » 12 Jun 2018, 17:08

Hi MannyKSoSo, I've been messing with this for a little while, and haven't got the COM part of it working yet.
This code, while not COM, does work.
Spoiler

I'm not sure if the JS object for Acrobat takes the same arguments as the AHK Com object, but the code you provided:

Code: [Select all]GeSHi © Codebox Plus

oAcrobat.saveAs(A_ScriptDir "FileToRead.xml", "com.adobe.acrobat.xml-1-00")

appears to be for JavaScript, which Acrobat of course can use extensively.

If I get any closer, I'll post my results.
Regards,
burque505

Re: Adobe Acrobat Pro via COM

Post by MannyKSoSo » 12 Jun 2018, 16:56

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

Code: [Select all]GeSHi © Codebox Plus

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!

Re: Adobe Acrobat Pro via COM

Post by FanaticGuru » 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

Re: Adobe Acrobat Pro via COM

Post by FanaticGuru » 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]GeSHi © Codebox Plus

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]GeSHi © Codebox Plus

/*
[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

Re: Adobe Acrobat Pro via COM

Post by MannyKSoSo » 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] [Expand]GeSHi © Codebox Plus



Any thoughts?

Re: Adobe Acrobat Pro via COM

Post by toopy » 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?

Re: Adobe Acrobat Pro via COM

Post by Blackholyman » 21 Sep 2015, 03:58

Not that I know of the top of my head sorry...

Re: Adobe Acrobat Pro via COM

Post by toopy » 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?

Re: Adobe Acrobat Pro via COM

Post by Blackholyman » 20 Sep 2015, 17:22

@Tank
Absolutely :)

@toopy
Know of one you can try oAcrobat.MenuItemExecute("Cpt:CapturePages")

Re: Adobe Acrobat Pro via COM

Post by toopy » 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?

Re: Adobe Acrobat Pro via COM

Post by tank » 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

Re: Adobe Acrobat Pro via COM

Post by Blackholyman » 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] [Expand]GeSHi © Codebox Plus



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]GeSHi © Codebox Plus



Hope it helps

Top