Will my VBA code for Adobe Acrobat 11 Pro work if I upgrade to Acrobat DC?

rogerdjr
rogerdjr used Ask the Experts™
on
I use Adobe acrobat XI Pro version 11.0.22 extensively

Have vba code that edits (E) acrobat files adding headers and footers and shrinking file sizes

I understand that Adobe will stop supporting this software on October and they recommend an upgrade

Any advice on the upgrade - how will it affect my code applications?

Examples are

--------------------------------------
Option Compare Database
Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Private Declare PtrSafe Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As LongPtr, ByVal wFlag As LongPtr) As Long
Private Declare PtrSafe Function GetTopWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long

Private Const GW_HWNDNEXT = 2
Private Const WM_CLOSE = &H10

Public Function MakeEvenPageCount(ByVal SourcePath As String, ByVal SourceFileName As String, ByVal DestPath As String, ByVal DestFileName As String, ByVal FrstPg As Double, ByVal MaxNoPgs As Double, ByVal FileNo As Double, ByVal DoYouWantToSendToPrinter As Integer, ByVal FontSize As Integer, ByVal FontColor As String) As String '07-25-2011, ByVal DoYouWantToInclPathInFtr As Integer) As String
    Dim ex1 As String
    Dim App As Object, AVDoc As Object, AcroPDDoc As Object, AForm As Object
    
    Dim Ret As Long
    Dim sString As String * 255
    Dim PdfPrint As String, numPages As Integer, numPages1 As Integer
        
    Dim sfile As String
    Dim sText As String
    Dim iFilenum As Integer
    
    Dim fileName As String '06-18-2011
    
    Set App = CreateObject("Acroexch.app")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    Set AVDocBlank = CreateObject("AcroExch.AVDoc")
    Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
    
    If Right(SourcePath, 1) <> "\" Then SourcePath = SourcePath & "\"
    If Right(DestPath, 1) <> "\" Then DestPath = SourcePath & "\"
   
    WorkingDriveLetter = Left(CurrentProject.Path, 1)

    fileName = SourceFileName '06-18-2011
    booleanresult = AVDoc.Open(SourcePath & SourceFileName, "")
        
    If booleanresult = True Then
        Set AcroPDDoc = AVDoc.GetPDDoc
        
        numPages = AcroPDDoc.GetNumPages()

        If Int(numPages / 2) <> numPages / 2 Then

            booleanresult1 = AVDocBlank.Open(WorkingDriveLetter & ":\Projects\_CM-OwnerRep\ProjMngmtDataBase\ThisPageIntentionallyBlank.pdf", "")

        
            If booleanresult1 = True Then Set BlankPage = AVDocBlank.GetPDDoc
        
            If AcroPDDoc.InsertPages(numPages - 1, BlankPage, 0, BlankPage.GetNumPages(), True) = True Then
                numPages = numPages + 1
            End If
        End If
    End If
    
    AcroPDDoc.Save 1, DestPath & DestFileName
    AcroPDDoc.Close
    AVDoc.Close (True)
    App.Exit
    
    Set AcroPDDoc = Nothing
    Set AVDoc = Nothing
    Set App = Nothing
End Function

Public Function AddPageNumbers(ByVal SourcePath As String, ByVal SourceFileName As String, ByVal DestPath As String, ByVal DestFileName As String, ByVal FrstPg As Double, ByVal MaxNoPgs As Double, ByVal FileNo As Double, ByVal DoYouWantToSendToPrinter As Integer, ByVal FontSize As Integer, ByVal FontColor As String, Optional RotatePageDegrees As Integer, Optional HeaderFooter As String) ', ByVal SupressNoPrintMsg As Boolean) As String '07-25-2011, ByVal DoYouWantToInclPathInFtr As Integer) As String

'https://acrobatusers.com/tutorials/watermarking-a-pdf-with-javascript

    Dim ex1 As String
    Dim App As Object, AVDoc As Object, AcroPDDoc As Object, AForm As Object
    
    Dim Ret As Long
    Dim sString As String * 255
    Dim PdfPrint As String, numPages As Integer, numPages1 As Integer, PageNoVar As Integer
        
    Dim sfile As String
    Dim sText As String
    Dim iFilenum As Integer
    
    Dim fileName As String '06-18-2011
    
    Set App = CreateObject("Acroexch.app")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    
    Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
    
    If Right(SourcePath, 1) <> "\" Then SourcePath = SourcePath & "\"
    If Right(DestPath, 1) <> "\" Then DestPath = SourcePath & "\"
   
    fileName = DestFileName '06-18-2011

    booleanresult = AVDoc.Open(SourcePath & SourceFileName, "")
        
        

    If booleanresult = True Then
        Set AcroPDDoc = AVDoc.GetPDDoc
        
            If Not IsNull(RotatePageDegrees) Then
             numPages = AcroPDDoc.GetNumPages()
                For PageNoVar = 0 To numPages - 1
                    Dim PDFPage As AcroPDPage
                    Set PDFPage = AcroPDDoc.AcquirePage(PageNoVar)
                    Call PDFPage.SetRotate(0)
                    Call PDFPage.SetRotate(RotatePageDegrees)
                Next
            End If

         'Found Code at this web page https://forums.adobe.com/thread/721676?start=0&tstart=0
         'Java Script manual at http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf
         'Expert Exchange Question at http://www.experts-exchange.com/Web_Development/Document_Imaging/Adobe_Acrobat/Q_28569754.html
         
       
         
         

    
    PageNoVar = 0
    
    While PageNoVar <= numPages
    
        ex1 = "this.addWatermarkFromText({" & vbLf

        ex1 = ex1 & "cText: " & """" & fileName & " -- " & Format(Now(), "mm-dd-yyyy hh:mm") & " " & PageNoVar + 1 & " of " & numPages & """" & "," & vbLf

        ex1 = ex1 & "nTextAlign:app.constants.align.center," & vbLf
        
        If HeaderFooter = "Header" Then
            ex1 = ex1 & "nVertAlign:app.constants.align.top," & vbLf
        Else
            ex1 = ex1 & "nVertAlign:app.constants.align.bottom," & vbLf
        End If
        
        ex1 = ex1 & "cFont: " & """" & "Helvetica-Bold" & """" & "," & vbLf
        ex1 = ex1 & "nFontSize: " & FontSize & "," & vbLf
        ex1 = ex1 & "aColor: color.red," & vbLf
        ex1 = ex1 & "nStart: " & PageNoVar & "," & vbLf
        ex1 = ex1 & "nOpacity: 0.5" & vbLf
        ex1 = ex1 & "});"
        
        PageNoVar = PageNoVar + 1
            

            

        
        AForm.Fields.ExecuteThisJavaScript ex1
    Wend
    
    End If
    
    
    On Error Resume Next
    
    AcroPDDoc.Save 1, DestPath & DestFileName
    
    numPages = AcroPDDoc.GetNumPages()
    
        sfile = DestPath & "Files Printed " & Format$(Now, "YYMMDD") & ".txt"
        sText = IIf(FileNo < 10, "00", IIf(FileNo < 100, "0", "")) & FileNo & " --- " & "Printed " & MaxNoPgs & " of " & IIf(numPages < 10, "00", IIf(numPages < 100, "0", "")) & numPages & " --- " & SourcePath & SourceFileName & " --- " & DestPath & DestFileName
        
        If FileNo = 1 Then Kill DestPath & "Files Printed " & Format$(Now, "YYMMDD") & ".txt"
        
        iFilenum = FreeFile
        Open sfile For Append As iFilenum
        Write #iFilenum, sText
        Close #iFilenum
    
    If MaxNoPgs >= numPages Then
        MaxNoPgs = numPages
    End If
    
On Error GoTo 0
    
    AcroPDDoc.Close
    AVDoc.Close (True)
    App.Exit
    
    Set AcroPDDoc = Nothing
    Set AVDoc = Nothing
    Set App = Nothing

    If DoYouWantToSendToPrinter = 6 Then
        'http://help.adobe.com/livedocs/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat10_SDK_HTMLHelp&file=DevFAQ_UnderstandingSDK.22.31.html
        appPDF = """" & "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe" & """"
        RetVal = Shell(appPDF & " /t /h /s /o " & """" & DestPath & DestFileName & """" & " Adobe PDF", 0)
    Else
    
    End If

End Function

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jackie Man IT Manager
Top Expert 2010

Commented:
What is the OS?

Author

Commented:
2 Computers 1- windows 8.1 the other windows 10
Office 365 enterprise e3
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
Hi Roger,
I haven't studied all 192 lines of your code carefully, but based upon a quick review, one problem I see is this line that has the hard-coded path to the Acrobat executable:

C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe

Open in new window

In Acrobat Pro DC, that path will be:

c:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe

Open in new window

Other than that, I think the script will work. But instead of guessing, try it. Download the free Acrobat Pro DC trial from here:
https://acrobat.adobe.com/us/en/free-trial-download.html

I suggest installing it on a test machine so that you don't mess up the Acrobat XI Pro that is on your production machine. Regards, Joe

Author

Commented:
Worked great thanks
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome, Roger, I'm glad that worked for you. Regards, Joe

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial