Jump to content

Acro.au3 UDF


Recommended Posts

You'll want to take a look at the Acrobat JavaScript API here. To get an array of all bookmarks and their sublevel, check out the JavaScript example under Bookmark.children... they print out the names of all of the bookmarks with spaces to indicate the level.

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

seadoggie01,

Don't shoot me just yet - I'm trying to understand what the structure is.  At the bottom of the code is my note on where I'm stuck.

Any help appreciated.

;
;v1n - stripped down to show where I'm stuck
;Acro.au3 test program
#AutoIt3Wrapper_run_debug_mode=Y    ; use this to debug in console window <--- LOOK

#include <Acro.au3>

MsgBox(0, "Test", "Testing Acro UDF")

;open one of the test files
$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Bookmark test document pp 1-4 w a-d sub levels.pdf"
;$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Bookmark test document pp 1-4 w no bookmarks.pdf"
$oPdDoc = _Acro_DocOpen($sFullPath)
If $oPdDoc = False Then
    If @error = 1 Then MsgBox(0, "Error", "Could not find file: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not opened: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document opened: '" & $sFullPath &"'")
EndIf


;get page count         ;page count is Zero based!! SO it goes from 0 to $iPage-1
$iPages = _Acro_PageCount($oPdDoc)
If $iPages = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Can't get number of pages in: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", $iPages & " pages in document: '" & $sFullPath &"'")
EndIf


;v1m - ;Brute force until I understand JS

Local $oJS = _Acro_DocJSObject($oPdDoc)     ; $oJS is now equal to "this" in the JavaScript reference
Local $oRootBkmk = $oJS.bookmarkRoot        ; Get the root level bookmark, an imaginary bookmark that doesn't display, but holds all other top level bookmarks

MsgBox(0, "Debug", "$oRootBkmk = '" & $oRootBkmk &"'")

Local $oRootBkmkName = $oRootBkmk.name
If $oRootBkmkName = Null Then
    MsgBox(0, "Debug", "There are no bookmarks in file: '" & $sFullPath &"'")   ;wrong even with no BMs the $oRootBkmkName = 'Root' it may just not have any children
Else
    MsgBox(0, "Debug", "$oRootBkmkName = '" & $oRootBkmkName &"'")  ;normally 'Root'
EndIf

;check for any children
Local $oRootBkmkChildren = $oRootBkmk.children
MsgBox(0, "Debug", "$oRootBkmkChildren = '" & $oRootBkmkChildren &"'")
If $oRootBkmkChildren = Null Then
    MsgBox(0, "Debug", "There are no bookmarks in file: '" & $sFullPath &"'")   ;there are no children of Root
Else
    MsgBox(0, "Debug", "There are bookmarks.")  ;we have at least one child
EndIf

;using test file with bookmarks = "Bookmark test document pp 1-4 w a-d sub levels.pdf"
;I get
;0047: 0-0: Local $oRootBkmkChildren = $oRootBkmk.children
;"C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Acro UDF testing v1n_DebugIt.au3" (132) : ==> The requested action with this object has failed.:
;Local $oRootBkmkChildren = $oRootBkmk.children
;Local $oRootBkmkChildren = $oRootBkmk^ ERROR

;using test file with NO bookmarks = "Bookmark test document pp 1-4 w no bookmarks.pdf"
;I get the msg "There are bookmarks."
;clearly I don't understand what's going on


Exit

 

Bookmark test document pp 1-4 w a-d sub levels.pdf Bookmark test document pp 1-4 w no bookmarks.pdf

Link to comment
Share on other sites

You're getting a COM Error when you use the .children property of a bookmark without any children. These functions will print the bookmark names for a document:

; <Requires Acro.au3> 

; #FUNCTION# ====================================================================================================================
; Name ..........: _Acro_DocBookmarksPrint
; Description ...: Prints the Bookmark structure to the Console
; Syntax ........: _Acro_DocBookmarksPrint($oPdDoc)
; Parameters ....: $oPdDoc              - an object.
; Return values .: Success - None
;                  Failure - False and sets @error:
;                  |1 - $oPdDoc is not a PDDoc
;                  |2 - Unable to get the root bookmark object, @extended is set to the COM Error
;                  |3 - $oPdDoc doesn't have any Bookmarks
; Author ........: Seadoggie01
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Acro_DocBookmarksPrint($oPdDoc)

    If Not __Acro_ObjCheck($oPdDoc, "PDDoc") Then Return SetError(1, 0, False)

    Local $oJavaScript = _Acro_DocJSObject($oPdDoc)

    ; Create an Error handler (Captures COM Errors: see ObjEvent in the help file for more info)
    Local $oError = ObjEvent("AutoIt.Error", __Acro_ErrHnd)
    #forceref $oError

    Local $oBmkRoot = $oJavaScript.bookmarkRoot
    ; If we get a COM error, Return an error and set @extended to the COM error
    If @error Then Return SetError(2, @error, False)

    __Acro_BookmarkPrintChildren($oBmkRoot, "")
    If @error Then Return SetError(3, 0, False)

EndFunc

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __Acro_BookmarkPrintChildren
; Description ...: (Depth first) Recursive function: Prints all child bookmark names
; Syntax ........: __Acro_BookmarkPrintChildren($oBookmark, $sLevel)
; Parameters ....: $oBookmark           - an object.
;                  $sLevel              - a string value.
; Return values .: None
; Author ........: Seadoggie01
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func __Acro_BookmarkPrintChildren($oBookmark, $sLevel)

    ; Create an Error handler (Captures COM Errors: see ObjEvent in the help file for more info)
    Local $oError = ObjEvent("AutoIt.Error", __Acro_ErrHnd)
    #forceref $oError

    ; Print the name indented to the $iLevel
    ConsoleWrite($sLevel & $oBookmark.Name & @CRLF)

    Local $aoChildren = $oBookmark.children ; <--- You're right, the .Children property never returns Null, it gets a COM error: -2147352570
    If @error Then
        Return SetError(1, 0, False)
    Else
        For $i=0 To UBound($aoChildren) - 1
            __Acro_BookmarkPrintChildren($aoChildren[$i], $sLevel & " ")
        Next
    EndIf

EndFunc

Take a look ObjEvent for a better explanation of COM Errors than I can give :)

Edit: And I won't shoot you, I'll just respond in my own time :D No really though, I completely understand. I've been swamped at work lately so I haven't had much time lately, but I promise to make more Bookmark related functions... eventually!

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

seadoggie01,

Nicely done :)

I integrated the functions into acro.au3 and they work like a charm.  I'll look into ObjEvent and try and understand it.

Whenever you get to additional functions is fine.  I'm kinda buried in the middle of some work as well.

;
;v1o - using new _Acro_DocBookmarksPrint
;Acro.au3 test program
#AutoIt3Wrapper_run_debug_mode=Y    ; use this to debug in console window <--- LOOK

#include <Acro.au3>

MsgBox(0, "Test", "Testing Acro UDF")

;open one of the test files
$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Bookmark test document pp 1-4 w a-d sub levels.pdf"
;$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Bookmark test document pp 1-4 w no bookmarks.pdf"
$oPdDoc = _Acro_DocOpen($sFullPath)
If $oPdDoc = False Then
    If @error = 1 Then MsgBox(0, "Error", "Could not find file: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not opened: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document opened: '" & $sFullPath &"'")
EndIf


;get page count         ;page count is Zero based!! SO it goes from 0 to $iPage-1
$iPages = _Acro_PageCount($oPdDoc)
If $iPages = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Can't get number of pages in: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", $iPages & " pages in document: '" & $sFullPath &"'")
EndIf

;print to console the bookmark structure
ConsoleWrite("!This should show the bookmark structure for: '" & $sFullPath &"'"& @CRLF)
$x = _Acro_DocBookmarksPrint($oPdDoc)

If $x = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Unable to get the root bookmark object, @extended is set to the COM Error")
    If @error = 3 Then MsgBox(0, "Info", "No bookmarks in: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Bookmark structure in console window.")
EndIf

MsgBox(0, "Debug", "Before Exit.")

Exit

 

Bookmark test document pp 1-4 w a-d sub levels.pdf Bookmark test document pp 1-4 w no bookmarks.pdf

Link to comment
Share on other sites

  • 2 weeks later...

I've created a GitHub repository for this, check it out in my signature (in just a minute or two). I've added a few _Acro_DocBookmark functions as well as some other changes :)

Edit: Can't figure out how to change my signature right now. https://github.com/seadoggie01/Acro.au3

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Thanks for all the new functions.  (Sorry for the delay - long story short my system crashed and a cloned drive refused to boot 😬.)  I'm trying to test the functions out now.  I feel like a dummy.  What is a visible Acrobat application object supposed to look like?  That is, should an Acrobat window open?  From the code below I see nothing on my screen.  My confusion is because I see nothing and _Acro_AppShow (which is called by _Acro_AppCreate) states: Shows and hides the Acrobat Application

;
;v1a - using new Acro1.0.1.0
;Acro1.0.1.0.au3 test program
#AutoIt3Wrapper_run_debug_mode=Y    ; use this to debug in console window <--- LOOK

#include <Acro1.0.1.0.au3>

MsgBox(0, "Test", "Testing Acro1.0.1.0 UDF")

MsgBox(0, "Test", "About to create a visible Acrobat Application object.")
;be aware that if one or more Acrobat pdf documents are opened or in the background or iconed one will become visible and opened.

$oAcroApp = _Acro_AppCreate()   ;default is visible
If $oAcroApp = False Then
    If @error = 1 Then MsgBox(0, "Error", "Unable to create applicaiton.")
    If @error = 2 Then MsgBox(0, "Error", "Unable to set visibility.")
Else
    ;$oAcroApp = 0  ;debug
    If IsObj($oAcroApp) Then
        $x = ""
    Else
        $x = " NOT"
    EndIf
    MsgBox(0, "Okay", "Acrobat Application object" & $x &" created.")
EndIf

 

Link to comment
Share on other sites

  • 6 months later...

Here are two more functions for consideration:

; #FUNCTION# ====================================================================================================================
; Name ..........: _Acro_DocGetInfo
; Description ...: Gets document properties
; Syntax ........: _Acro_DocGetInfo($oPdDoc, $sInfoKey)
; Parameters ....: $oPdDoc              - an object.
;                  $sInfoKey            - a string value.
; Return values .: Success - Requested value of info key
;                  Failure - False and Gets @error:
;                  |1 - $oPdDoc isn't a PDDoc object
;                  |2 - $sInfoKey is invalid
;                  |3 - Unable to get info
; Author ........: GMK
; Modified ......: Mar 18, 2021 (@09:33:27)
; Remarks .......:
; Related .......:
; Links .........: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FIAC_API_OLE_Objects%2FGetInfo.htm
;                  https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2Fpdfmark_Basic%2FDocument_Info_dictionary_DOCINFO.htm
; Example .......: No
; ===============================================================================================================================
Func _Acro_DocGetInfo($oPdDoc, $sInfoKey)

    If Not __Acro_ObjCheck($oPdDoc, "PDDoc") Then Return SetError(1, 0, False)

    If $sInfoKey <> 'Author' And _
            $sInfoKey <> 'CreationDate' And _
            $sInfoKey <> 'Creator' And _
            $sInfoKey <> 'Producer' And _
            $sInfoKey <> 'Title' And _
            $sInfoKey <> 'Subject' And _
            $sInfoKey <> 'Keywords' And _
            $sInfoKey <> 'ModDate' Then _
            Return GetError(2, 0, False)

    Local $sReturn = $oPdDoc.GetInfo($sInfoKey)
    If $sReturn = -1 Then Return SetError(3, 0, False)
    Return SetError(0, 0, $sReturn)

EndFunc   ;==>_Acro_DocGetInfo

; #FUNCTION# ====================================================================================================================
; Name ..........: _Acro_DocSetInfo
; Description ...: Sets document properties
; Syntax ........: _Acro_DocSetInfo($oPdDoc, $sInfoKey, $sBuffer)
; Parameters ....: $oPdDoc              - an object.
;                  $sInfoKey            - a string value.
;                  $sBuffer             - a string value.
; Return values .: Success - True
;                  Failure - False and sets @error:
;                  |1 - $oPdDoc isn't a PDDoc object
;                  |2 - $sInfoKey is invalid
;                  |3 - Info not set
; Author ........: GMK
; Modified ......: Mar 18, 2021 (@09:33:27)
; Remarks .......:
; Related .......:
; Links .........: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FIAC_API_OLE_Objects%2FSetInfo.htm
;                  https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2Fpdfmark_Basic%2FDocument_Info_dictionary_DOCINFO.htm
; Example .......: No
; ===============================================================================================================================
Func _Acro_DocSetInfo($oPdDoc, $sInfoKey, $sBuffer)

    If Not __Acro_ObjCheck($oPdDoc, "PDDoc") Then Return SetError(1, 0, False)

    If $sInfoKey <> 'Author' And _
            $sInfoKey <> 'CreationDate' And _
            $sInfoKey <> 'Creator' And _
            $sInfoKey <> 'Producer' And _
            $sInfoKey <> 'Title' And _
            $sInfoKey <> 'Subject' And _
            $sInfoKey <> 'Keywords' And _
            $sInfoKey <> 'ModDate' Then _
            Return SetError(2, 0, False)

    If Not ($oPdDoc.SetInfo($sInfoKey, $sBuffer) = -1) Then Return SetError(3, 0, False)
    Return SetError(0, 0, True)

EndFunc   ;==>_Acro_DocSetInfo

 

Edited by GMK
Added a function; edited function
Link to comment
Share on other sites

@GMK I'd suggest two things: ;)

1. Try your code... PdDoc.GetInfo doesn't accept two parameters and _Acro_DocSetInfo doesn't return True if there's not an error

2. I'd likely combine these into a single function: _Acro_DocInfo($oPdDoc, $sInfoKey, $sValue = Default)... which calls .GetInfo if $sValue = Default or .SetInfo if not

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

One Two more questions if you don't mind... is it only possible to get/set those 8 values? I've seen extra properties in adobe docs before. Also, do they need to be capitalized?

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

As far as I know, it's only those eight values with the GetInfo/SetInfo method.  As far as capitalization, that's a good question.  I'll have to do some testing.  Obviously, that would change error checking.

Link to comment
Share on other sites

Maybe something like this would be better:

; #FUNCTION# ====================================================================================================================
; Name ..........: _Acro_DocInfo
; Description ...: Gets or sets document properties
; Syntax ........: _Acro_DocInfo($oPdDoc[, $sInfoKey = Default[, $sBuffer = Default]])
; Parameters ....: $oPdDoc              - an object.
;                  $sInfoKey            - (optional) string value of Author, CreationDate, Creator, Producer, Title, Subject,
;                                         Keywords or ModDate.
;                  $sBuffer             - Value, if setting value of $sInfoKey
; Return values .: Success - If no info key and buffer are provided, returns an array:
;                            $avArray[0] = Title
;                            $avArray[1] = Author
;                            $avArray[2] = Creator
;                            $avArray[3] = Producer
;                            $avArray[4] = Title
;                            $avArray[5] = Subject
;                            $avArray[6] = Keywords
;                            $avArray[7] = ModDate
;                            If $sInfoKey and $sBuffer key are specified, return True
;                  Failure - False and Gets @error:
;                  |1 - $oPdDoc isn't a PDDoc object
;                  |2 - $sInfoKey is invalid
;                  |3 - Unable to get/set Info
; Author ........: GMK
; Modified ......: Mar 22, 2021 (@10:33:37)
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Acro_DocInfo($oPdDoc, $sInfoKey = Default, $sBuffer = Default)

    If Not __Acro_ObjCheck($oPdDoc, "PDDoc") Then Return SetError(1, 0, False)

    Local $avReturn = [ _
            ['Title', $oPdDoc.GetInfo('Title')], _
            ['Author', $oPdDoc.GetInfo('Author')], _
            ['Subject', $oPdDoc.GetInfo('Subject')], _
            ['Keywords', $oPdDoc.GetInfo('Keywords')], _
            ['Creator', $oPdDoc.GetInfo('Creator')], _
            ['Producer', $oPdDoc.GetInfo('Producer')], _
            ['CreationDate', $oPdDoc.GetInfo('CreationDate')], _
            ['ModDate', $oPdDoc.GetInfo('ModDate')]]

    Select
        Case IsKeyword($sInfoKey)
            Return SetError(0, 0, $avReturn)
        Case $sInfoKey = 'author'
            $sInfoKey = 'Author'
        Case $sInfoKey = 'creationdate'
            $sInfoKey = 'CreationDate'
        Case $sInfoKey = 'creator'
            $sInfoKey = 'Creator'
        Case $sInfoKey = 'producer'
            $sInfoKey = 'Producer'
        Case $sInfoKey = 'title'
            $sInfoKey = 'Title'
        Case $sInfoKey = 'subject'
            $sInfoKey = 'Subject'
        Case $sInfoKey = 'keywords'
            $sInfoKey = 'Keywords'
        Case $sInfoKey = 'moddate'
            $sInfoKey = 'ModDate'
        Case _ArraySearch($avReturn, $sInfoKey) = -1
            Return SetError(2, 0, False)
    EndSelect

    Local $fReturn = $oPdDoc.SetInfo($sInfoKey, $sBuffer)
    Return SetError(0, 0, $fReturn)

EndFunc   ;==>_Acro_DocInfo

 

Link to comment
Share on other sites

I like the idea of returning an array of properties, I can see that being useful!

It looks like you don't allow the user to get a single property value now though... so if I call _Acro_DocInfo($oPdDoc, "Keywords") it will clear the keywords property. :( To fix it, I'd do this instead...

; #FUNCTION# ====================================================================================================================
; Name ..........: _Acro_DocInfo
; Description ...: Gets or sets the document properties of a PdDoc
; Syntax ........: _Acro_DocInfo($oPdDoc, $sInfoKey[, $sBuffer = Default])
; Parameters ....: $oPdDoc              - a PdDocument object.
;                  $sInfoKey            - a string value. See remarks.
;                  $sBuffer             - [optional] a string value. Default gets the current value.
; Return values .: Success - the current value of the property
;                  Failure - False and sets @error:
;                  |1 - $oPdDoc is not a PDDocument object
;                  |2 - $sInfoKey is not supported
;                  |3 - Unable to set document property
;                  |4 - Unable to get current document property
; Author ........: GMK, Seadoggie01
; Modified ......: March 22, 2021
; Remarks .......: Supported $sInfoKey values: author, creationdate, creator, producer, title, subject, keywords, and moddate
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func _Acro_DocInfo($oPdDoc, $sInfoKey, $sBuffer = Default)

    If Not __Acro_ObjCheck($oPdDoc, "PDDoc") Then Return SetError(1, 0, False)

    Local $sOptions = "author|creationdate|creator|producer|title|subject|keywords|moddate|"
    If Not StringInStr($sOptions, StringLower($sInfoKey & "|")) Then Return SetError(2, 0, False)
    
    If IsKeyword($sInfoKey) Then
        ; Split the options to get their values
        Local $aOptions = StringSplit(StringTrimRight($sOptions, 1), "|", 3)
        Local $aRet[UBound($aOptions)][2]
        For $i=0 To UBound($aOptions) - 1
            $aRet[$i][0] = $aOptions[$i]
            $aRet[$i][1] = $oPdDoc.GetInfo($aOptions[$i])
        Next
        Return $aRet
    EndIf
    
    If Not IsKeyword($sBuffer) Then
        If Not ($oPdDoc.SetInfo($sInfoKey, $sBuffer) = -1) Then Return SetError(3, 0, False)
    EndIf
    
    Local $sValue = $oPdDoc.GetInfo($sInfoKey)
    If ($sValue = "") Then Return SetError(4, 0, False)

    Return $sValue

EndFunc   ;==>_Acro_DocInfo

Also, this helps avoid writing the list of possible property values more than one time (well, twice including the header). Cause, ya know, I'm lazy and don't want to update things a bunch :D

Btw, don't take this as criticism, or at least take it as constructive criticism? I'm really thankful someone is using this, thinking about it, and helping!!!

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

I'm always tweaking.  I should just wait until my final version to post these things. 😄

Are you able to get your above code working?  It seems to me that the info keys are case-sensitive.

; #FUNCTION# ====================================================================================================================
; Name ..........: _Acro_DocInfo
; Description ...: Gets or sets document properties
; Syntax ........: _Acro_DocInfo($oPdDoc[, $sInfoKey = Default[, $sBuffer = Default]])
; Parameters ....: $oPdDoc              - a PdDocument object.
;                  $sInfoKey            - [optional] a string value. See remarks.
;                  $sBuffer             - [optional] a string value. Default gets the current value.
; Return values .: Success - If no info key and buffer are provided, returns an array:
;                            $avArray[0] = Title
;                            $avArray[1] = Author
;                            $avArray[2] = Creator
;                            $avArray[3] = Producer
;                            $avArray[4] = Title
;                            $avArray[5] = Subject
;                            $avArray[6] = Keywords
;                            $avArray[7] = ModDate
;                            If only $sInfoKey is provided, return current value
;                            If $sInfoKey and $sBuffer key are provided, return True
;                  Failure - False and Gets @error:
;                  |1 - $oPdDoc is not a PDDocument object
;                  |2 - $sInfoKey is not supported
;                  |3 - Unable to get current document property
;                  |4 - Unable to set document property
; Author ........: GMK, Seadoggie01
; Modified ......: Mar 22, 2021
; Remarks .......: Supported $sInfoKey values: Title, Author, Creator, Producer, Title, Subject, Keywords and ModDate
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Acro_DocInfo($oPdDoc, $sInfoKey = Default, $sBuffer = Default)

    If Not __Acro_ObjCheck($oPdDoc, "PDDoc") Then Return SetError(1, 0, False)

    Select
        Case StringLower($sInfoKey) = 'title'
            $sInfoKey = 'Title'
        Case StringLower($sInfoKey) = 'author'
            $sInfoKey = 'Author'
        Case StringLower($sInfoKey) = 'subject'
            $sInfoKey = 'Subject'
        Case StringLower($sInfoKey) = 'keywords'
            $sInfoKey = 'Keywords'
        Case StringLower($sInfoKey) = 'creator'
            $sInfoKey = 'Creator'
        Case StringLower($sInfoKey) = 'producer'
            $sInfoKey = 'Producer'
        Case StringLower($sInfoKey) = 'creationdate'
            $sInfoKey = 'CreationDate'
        Case StringLower($sInfoKey) = 'moddate'
            $sInfoKey = 'ModDate'
        Case Not IsKeyword($sInfoKey)
            Return SetError(2, 0, False)
    EndSelect

    If IsKeyword($sInfoKey) Then
        Local $sInfoKeys = 'Title|Author|Subject|Keywords|Creator|Producer|CreationDate|ModDate'
        Local $asSplit = StringSplit($sInfoKeys, '|', 2)
        Local $avReturn[UBound($asSplit)][2]
        For $iKey = 0 To UBound($asSplit) - 1
            $avReturn[$iKey][0] = $asSplit[$iKey]
            $avReturn[$iKey][1] = $oPdDoc.GetInfo($asSplit[$iKey])
        Next
        Return SetError(0, 0, $avReturn)
    EndIf

    Local $vReturn
    If Not IsKeyword($sInfoKey) And IsKeyword($sBuffer) Then
        $vReturn = $oPdDoc.GetInfo($sInfoKey)
        If Not $vReturn Then Return SetError(3, 0, False)
    Else
        $vReturn = $oPdDoc.SetInfo($sInfoKey, $sBuffer)
        If Not $vReturn Then Return SetError(4, 0, False)
    EndIf

    Return SetError(0, 0, $vReturn)

EndFunc   ;==>_Acro_DocInfo

 

Edited by GMK
Added code
Link to comment
Share on other sites

  • 2 months later...

 

2 hours ago, pagkly said:

so wondering if this udf can do the same. 

Yes

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

On 5/23/2021 at 6:28 AM, pagkly said:

Wondering if this udf can handle pdf conversion?

What kind of files are you trying to convert to PDF? By default, opening a .tif file in Acrobat will convert it to a PDF, but you need to use an AVDoc instead of a PDDoc. I haven't tested other image file types, but I think the standard ones would work as well. When in doubt, try it! :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

  • 3 months later...

@seadoggie01 be so kind and add some tag to the topic. I propose:

  • udf
  • pdf
Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
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
 Share

×
×
  • Create New...