Reputation: 21
I am working on a requirement where I am merging 14 individual PDF to single PDF file. Also I want to add page number to each page after merge.
Anyone have any idea how to add page number in PDF file using VBA?
I am doing coding in MS-Access 2010 VBA and to generate PDF I am using Adobe Acrobat Standard.
Upvotes: 0
Views: 4621
Reputation: 21
Path = "F:\Target.pdf"
'Path = Wscript.Arguments.Item(0)
Set App = CreateObject("Acroexch.app")
app.show
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
If AVDoc.Open(Path,"") Then
'//write JS-Code on a variable
Ex = " // Set Footer PageNo centered "&vbLF _
& " var Box2Width = 50 "&vbLF _
& " for (var p = 0; p < this.numPages; p++) "&vbLF _
& " { "&vbLF _
& " var aRect = this.getPageBox(""Crop"",p); "&vbLF _
& " var TotWidth = aRect[2] - aRect[0] "&vbLF _
& " { var bStart=((TotWidth/2)-(Box2Width/2)) " & vbLf _
& " var bEnd=((TotWidth/2)+(Box2Width/2)) + 5 "&vbLF _
& " var fp = this.addField(String(""xftPage""+p+1), ""text"", p, [bStart,45,bEnd,15]); "&vbLF _
& " fp.value = ""Page: "" + String(p+1)+ ""/"" + this.numPages; "&vbLF _
& " fp.textSize=9; fp.readonly = true; "&vbLF _
& " fp.alignment=""right""; "&vbLF _
& " } "&vbLF _
& " } "
'//Execute JS-Code
AForm.Fields.ExecuteThisJavaScript Ex
App.Exit
end if
Upvotes: 1