How to get specific page numbers to each template (per language and Per instance) when the template itself repeatable | Community
Skip to main content
Level 6
March 1, 2026

How to get specific page numbers to each template (per language and Per instance) when the template itself repeatable

  • March 1, 2026
  • 2 replies
  • 53 views

Hello All,

We have a single template with English and Spanish pages combined, and the same template can repeat based on data. With this use case, how to get the page numbers specific to language and instance?

Currently it returns total page counts, as page number calculated on master page default script.

Any suggestions on this use case to achieve?

 

When data for one Instance:

<form>

<Template>

     <English>

     </English>

     <Spanish>

     </Spanish>

</Template>

</form>

 

When data for multiple Instances:

<form>

<Template>

     <English>

     </English>

     <Spanish>

     </Spanish>

</Template>

<Template>

     <English>

     </English>

     <Spanish>

     </Spanish>

</Template>

</form>

 

Thanks,

Raghu.

    2 replies

    VishalKa5
    Level 6
    March 2, 2026

    Hi ​@Raghu_Nagireddy ,

     

    • Page numbering placed on the Master Page uses xfa.layout.page() and xfa.layout.pageCount() which always calculate page numbers at the document level.

    • Master Pages do not recognize boundaries of repeating subforms (Template instances) or language sections (English/Spanish).

    • Since the Template subform is repeatable, instance-specific page numbering must be calculated at the subform level, not the Master Page level.

    • Move the page number field inside the repeating Template subform.

    • Use JavaScript in the layout:ready event to calculate the current page relative to the starting page of that Template instance.

    • Logic:

      • Get current page using xfa.layout.page(this)

      • Get starting page of the current Template instance

      • Subtract start page from current page and add 1

    • For language-specific numbering, wrap English and Spanish sections in separate subforms and calculate page numbers relative to each language subform.

    • Ensure the Template subform is set to Flowed and configured as Repeat Subform for Each Data Item.

    In summary:
    Master Page → Global page count
    Subform-level scripting → Instance-level and language-level page count.

     

    Thanks,
    Vishal

    Level 6
    March 2, 2026

    Hello Vishal,

    Thank you very much for checking on this issue. In this case, how to show the page number on footer as it moved the calculation out of master page? or expecting to use overflow trailer? Also the repeat is total template, not all English in one location then all Spanish. It should be English and corresponding Spanish, then next instance of English and corresponding Spanish. Please let me know if i missed something here? Sample pdf(can open in designer for template structure) for review: https://acrobat.adobe.com/id/urn:aaid:sc:US:c2c05977-ca63-4596-b3e1-d61c86a4ac0f 

    radzmar
    Level 10
    March 2, 2026

    Can you plaese provide a sample of your form and the scheme of how the numbering should look like? 

    Level 6
    March 2, 2026

    Hello radzmar,

    Thank you very much for checking on this.

    Please find the details below, for example, here template having 4 pages of English and 4 pages of Spanish. To have different language headers and footers, we have language specific master pages.

    The general default page numbering on left side and Master page index and length calculation on right side. Any kind of script is fine to get specific to each language and instance, all the time page numbers expecting to show as below.

    Page 1 of 4

    Page 2 of 4

    Page 3 of 4

    Page 4 of 4

    Currently template page numbers showing in the below way.

    Default page number script

    Master page index Script

    xfa.layout.page(this) of xfa.layout.pageCount()

    this.parent.index + 1 of this.parent.all.length

    Scenario 1: Template is not repeating and with one instance.

    Template

      TemplateEN  1 of 8………. 4 of 8

       TemplateSP  5 of 8………. 8 of 8

     

     

    Template

      TemplateEN  1 of 4………. 4 of 4

       TemplateSP  1 of 4………. 4 of 4

    Scenario 2: Template repeats and with two instances and it can grow as well.

    Template

      TemplateEN  1 of 16………. 4 of 16

       TemplateSP  5 of 16………. 8 of 16

     

    Template

      TemplateEN  9 of 16……….   12 of 16

       TemplateSP  13 of 16………. 16 of 16

     

     

    Template

      TemplateEN  1 of 8………. 4 of 8

       TemplateSP  1 of 8………. 4 of 8

     

    Template

      TemplateEN  5 of 8………. 8 of 8

       TemplateSP  5 of 8………. 8 of 8

     

    Please let me know if need any more details on this. To share XDP not seen file upload here. just saved as pdf and uploaded, please download from here. https://acrobat.adobe.com/id/urn:aaid:sc:US:c2c05977-ca63-4596-b3e1-d61c86a4ac0f

    radzmar
    Level 10
    March 9, 2026

    So you want an individual page count for each english and spanish subform? 

    Place a textfield “TemplateSpan” on each of the masterpages (Page1-Page2). Then add the following script into the calculate event of the subform “EnglishTemplate” and “SpanishTemplate”. It will populate the page counts to the field on the corresponding masterpages. 

    // Individual page count for subform spanning multiple pages.
    var nAbsPage = xfa.layout.absPage(this), // Absolute page num this subform begins (0-based)
    oPageArea = xfa.layout.pageContent(nAbsPage, "pageArea").item(0), // Reference to the master page used by the subform
    cPageName = oPageArea.name, // Name of the master page
    nSpan = xfa.layout.pageSpan(this), // Number of pages the subform spans
    nIndexStart = oPageArea.classIndex, // Index of first masterpage within span
    nIndexEnd = nIndexStart + nSpan, // Index of last masterpage within span
    // Resolve all master page instances that belong to this span
    oPageAreas = form1.resolveNodes('#pageSet.#pageArea.[$.name eq "' + cPageName + '" and $.classIndex ge ' + nIndexStart + ' and $.classIndex le ' + nIndexEnd + ']');

    // Populate page details to textfield "TemplateSpan" on related masterpage
    for (var i = 0; i < oPageAreas.length; i += 1) {
    var cTxt = "Page " + (1 + i) + " of " + nSpan;
    oPageAreas.item(i).TemplateSpan.rawValue = cTxt;
    }