Macro VBA - Add page numbers to existing pdf file

prati

Board Regular
Joined
Jan 25, 2021
Messages
51
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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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.
 
Upvote 0
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
 
Upvote 0
Hey

Does anyone have other ideas how to add numbers in the footer of a pdf file via VBA?
As I mentioned above, my method is to create pdf file containing 5000 empty pages (paper size a4), that only include numbers in the footer, so then I can "stamp" my file using PDFtk server.

A.pdf (without numbers) stamp Numbers.pdf output B.pdf (with numbers).

This method is good as long as I stamp A4 pages – portrait pages.

1632658979975.png


This method isn't proper because somtimes the file contain both portrait and landscape pages. In landscape pages the "numbers" look very tiny

1632658992299.png



Conclusion - stamping portrait page on landscape page may result at smaller stamping

Does anyone know how to add pages with a better attitude, rather than create empty 5000 pages that contain numbers and then stamp it with PDFtkserver?.
Should there be a way to add page numbers with ghostscript?
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,007
Members
448,935
Latest member
ijat

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
Back
Top