Skip to main content
Mae_RVT
Inspiring
November 5, 2019
Answered

Dynamic Section Headings with Spawned pages

  • November 5, 2019
  • 1 reply
  • 1724 views

Hi,

 

I have a built a PDF document in acrobat, where i have spawned pages included. I have achieved dynamic section headings (3.1, 3.2, 3.3 etc.) for the document using the following script for a first in line of spawn pages

 

event.value = "3." + ((event.target.page - 5) * 2);

this.calculateNow();

 

The problem that i am having is that using this style of code then also modifies section headings after where the spawn page is placed. I have 4 different spawn pages that slot in as additional test pages if needed. I need some help to be able to set a field to start from 1 and then subsequent add fields to find that field and add .1 to it, this needs to work across the spawned pages too.

 

I have attached a redacted version of the document, if you navigate to page 8 and use the button the add calibrations it works nicely, but then it changes the validation section headings and subsequent add on pages for validations too.

 

Any help would be appreciated, i have been trying to wrap my head around how to make it work. I thought about using this.numpages() but the total amount of the pages is always changing too.

 

P.S. Damn my boss for throwing this spanner into the works of an almost completed document!

 

This topic has been closed for replies.
Correct answer Mae_RVT

I think i just figured out why it wont work. Because there even though the original template is hidded, it still sees the button to add.field on it so there would be 2 of them which makes the calculation fail. I cant set the rename for the page to true as i have alot of linked calculations in there. Any guidance would be appreciated.


Ok... so now just talking to myself, but i thought i might post that i figured it out as it could help others.

 

What i did in the end, is created the following script to add the check box that spawns the pages (specific module of the document) to add the field to the last of the spawned pages which would be page 8 (there are 4)

var f = this.addField("VVA LINK", "text", 8, [10,30,80,10]);
f.display = display.hidden;

VVA LINK being the field name to reference for the extra spawn pages that can be made from the last page of the spawned module.

 

I used the following script to calculate the section numbers. Originally my JS console was going nuts with errors due to null values even if the extra pages were not spawned as they were trying to calculate in the background. I put the calculation into an if statement

if (this.numPages >= 13)
{
var VH = this.getField("VVA LINK").page;
var VVA = event.target.page;

event.value = "4." + (((VVA - VH) * 2) + 1);
this.calculateNow();
}
else
{}

This script references the page for the VVA LINK field that is hidden on the page before it, then uses the page numbers to calculate the difference between them to give you your section number (4.2, 4.3 etc.). It only calculates if the pages are equal to or greater than 13 pages, in my case, the document comes to 12 pages when the module is spawned. so i only want it to calculate if this extra page is added, making it 13+ pages.

 

Hope this can help out someone too.

 

 

1 reply

try67
Community Expert
Community Expert
November 5, 2019

I'm not sure what the issue is, exactly... I added a page and the headings on it are "3.5 Calibration Test" and "3.6 Calibration Test", which seems correct to me. Please clarify what you expect to happen instead.

Mae_RVT
Mae_RVTAuthor
Inspiring
November 5, 2019

Hi Try67,

 

that part works perfectly yes. I guess i didnt explain it very well sorry.

 

Although the calibration works well, if you look at the following pages, (Validation tests) you will see that the 4.1 and 4.2 jump to 4.3 and 4.4 because the page number is now different after spawning calibration pages, The numbers just keep climbing the more calibration pages that are spawned. I need these to be stagnant and the validation spawn pages to then count from 4.3/4.4+. 

 

The problem is after spawning for the calibration, all the validation section headings also jump. I do need these to be dynamic enough for the spawn pages for the validation section heading increments for additional validation pages.

 

I hope that makes some form of sense to you. I appreciate your help.

try67
Community Expert
Community Expert
November 5, 2019

I see what you mean. You can't do it based on the page number, then, since that is not predictable (ie, you can't know how many pages were spawned in each section).

Here's how I would do it: I would add a (hidden) field at the first page of each section and use that to calculate the amount of pages between it and the current page.