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.
DocSaveAs
Saves an open file to a new path. The user is not warned if there are any problems saving the file.
Syntax
[DocSaveAs(char* fullPath, char* newPath)]
Parameters
fullPath
The full path of the existing file.
newPath
The full path of the new file.
Returns
true if the document is saved successfully, false if the document does not exist or is not saved successfully.
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
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
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
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
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
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
If (FileExist(A_ScriptDir "\FileToRead.xml"))
FileDelete, %A_ScriptDir%\FileToRead.xml
Run, acrohelper.ahk
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")
Sleep, 1000
;Send, !FX
oAcrobat.MenuItemExecute("Close")
oAcrobatdoc := ""
OAcrobat := ""
WinKill, ahk_exe Acrobat.exe
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.)
Last edited by burque505 on 13 Jun 2018, 11:52, edited 1 time in total.
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).
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
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):
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
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
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
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