Macro VBA - Add page numbers to existing pdf file

prati

New Member
Joined
Jan 25, 2021
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
Hey,

I wonder if there is a way to add page numbers to existing pdf file through macro VBA, using a free way without adobe acrobat professional.

To be more specific I am already using PDFtk server for several tasks: merge/combine pdf pages, update bookmarks from TXT file inside pdf and other tasks.

In the manual of PDFtk server I don't see an option for adding page numbers - PDFtk Server Manual, however Mr. Angus Johnson and Mr. David King built a graphical application using PDFtk server that include an option to add page numbers.

1614094144236.png


1614094201945.png



This is the ini configuration file of the program/
1614095056969.png



I believe there should be a way to do it also through Macro VBA.

I have an assumption but it is like a guess.

Maybe the process should inculde three steps as follows:

1. Spliting the pdf to separate pages using "burst"
2. Stamp each page with the correct page number 1...2...3...4.....................5000...
3. Finally merge all the seprate pages into one combined pdf (the seprate pages should already include page numbers) using "cat".
I just made an assumption, I really don't know what is the right and elegant way for adding page numbers into existing pdf file.
If possible I prefer adding the numbers in the bottom center using 15 mm NumOffsetY (vertical distance from the bottom of the page)
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

prati

New Member
Joined
Jan 25, 2021
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
Of course - any other free solution for adding page numbers at the bottom center of a pdf file through Macro VBA would be great.
It does'nt have to be only with PDFtk server.
It just have to be a free way and not a paid one.
 

prati

New Member
Joined
Jan 25, 2021
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
I have found a way to insert page numbers with pdftk
First i created a pdf with 2000 pages via a graphical tool. Each page has only number at the bottom center. That file i have to keep in a folder at my computer, named it Numbers.

1617572038524.png


After that, it is pretty easy to insert numbers to every pdf file i wish.

Sub AddNumbers()

Dim Wshell As Object
Dim Wexec As Object
Dim Wsh As Object

Set Wsh = CreateObject("WScript.Shell") 'New WshShell
Set FSO = CreateObject("Scripting.FileSystemObject") 'New FileSystemObject

Set Wshell = CreateObject("WScript.Shell") 'New WshShell

''''Now all i have to to is to stamp the old.pdf file with the Numbers.pdf file and create a new.pdf file'''''

Wsh.Run ("cmd /c PDFtk " & "C:\Articles\Article without numbers.pdf" & " multistamp C:\NumbersFolder\Numbers.pdf output C:\Articles\Article including numbers.pdf"""), 0, True

End sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,485
Messages
5,636,606
Members
416,929
Latest member
Nitil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top