Help with PDF page number VBA (1 Viewer)

gojets1721

Registered User.
Local time
Today, 13:13
Joined
Jun 11, 2019
Messages
430
I found some VBA code online to add page numbers from Access to a PDF. It works but the formatting of the numbers is not ideal, and I'm admittedly unsure exactly what needs to be changed to achieve what I'm looking for. Here's the code:

Code:
Sub addPageNumbers()

    Dim acroApp As Acrobat.acroApp
    Dim myDocument As Acrobat.AcroPDDoc
    Dim jso As Object

    Dim strPath As String
    Dim strFileName As String
    Dim intPages As Integer
    Dim i As Integer

    Set acroApp = CreateObject("AcroExch.App")
    Set myDocument = CreateObject("AcroExch.PDDOc")

    strPath = "C:\"
    strFileName = "myDoc.pdf"

    'Open file and load JSObject
    Set myDocument = CreateObject("AcroExch.PDDOc")
    myDocument.Open (strPath & strFileName)
    Set jso = myDocument.GetJSObject

    ' get number of pages
    intPages = myDocument.GetNumPages

    'Write page numbers to all pages
    For i = 1 To intPages
        jso.addWatermarkFromText _
            cText:=Str(i) & "  ", _
            nTextAlign:=1, _
            nHorizAlign:=2, _
            nVertAlign:=4, _
            nStart:=i - 1, _
            nEnd:=i - 1
    Next i

    'Save document
    Call myDocument.Save(1, strPath & strFileName)

    'Clean up
    Set jso = Nothing
    Call acroApp.CloseAllDocs
    Set myDocument = Nothing
    Call acroApp.Exit
    Set acroApp = Nothing

End Sub

I want it to be Arial, size 8 and the bottom & right margin to both be .5. Any suggestions on if that can be achieved?
 

Users who are viewing this thread

Top Bottom