Skip to main content
Participant
July 15, 2024
Question

How to update or add page numbers dinamically using javascript?

  • July 15, 2024
  • 2 replies
  • 1036 views

Hello Acrobat community!
I hope everything is good with you..
I have a document which inittialy have 4 pages (already numberes using footer).
1. info
2. table
3. desc
4. signature

I have a button on page 3 (desc) that adds a template to the document, so my document becomes:

1. info
2. table
3. desc
4. addi
5. signature

The issue happens on page 4 which have no number on it and page 5 still displaying in the footer page 4.
Is there any way to fix this issue?
Thank you very much!

This topic has been closed for replies.

2 replies

PDF Automation Station
Community Expert
Community Expert
July 15, 2024

Use read only text fields and scripts if you want dynamic updating:

 

Nesa Nurani
Community Expert
Community Expert
July 15, 2024

You could use text fields instead, that updates with page number when you spawn template (script would need to run in same place where you spawn template after you spawn template)

Participant
July 16, 2024

Is there anyway to add a footer page numbers using javascript?
I will only add the page numbers when the user click a button to validate the form and print it.
Thank you for your reply, if there is no way of adding page number afterwords, then I will use the suggested method using text fields.

Nesa Nurani
Community Expert
Community Expert
July 16, 2024

You can try using this, modify it to your needs if needed, it can be used in a button (like when you submit):

for (var i = 0; i < this.numPages; i++) {
 var pageNumber = "Page " + (i + 1) + " of " + this.numPages;//here edit the look of the number (e.g., 'Page 1 of 3', or  1/3...etc
    
 var textProperties = {
 cFont: "Helvetica",
 nFontSize: 10,
 nStart: 10,
 cColor: color.black};
    
 var position = {
 nHorizAlign: app.constants.align.right,
 nVertAlign: app.constants.align.bottom,
 nHorizOffset: -40,
 nVertOffset: 20};
    
 this.addWatermarkFromText({
  cText: pageNumber,
  nTextAlign: app.constants.align.center,
  nHorizAlign: app.constants.align.center,
  nVertAlign: app.constants.align.bottom,
  nHorizOffset: 0,
  nVertOffset: 20,
  nFontSize: 10,
  nRotation: 0,
  bOnTop: true,
  nStart: i,
  nEnd: i});}