Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to update or add page numbers dinamically using javascript?

New Here ,
Jul 15, 2024 Jul 15, 2024

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!

TOPICS
How to , JavaScript
633
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2024 Jul 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2024 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2024 Jul 16, 2024
LATEST

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});}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2024 Jul 15, 2024

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines