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

Dynamic Section Headings with Spawned pages

Explorer ,
Nov 05, 2019 Nov 05, 2019

Copy link to clipboard

Copied

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!

 

TOPICS
Acrobat SDK and JavaScript

Views

975

Translate

Translate

Report

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

correct answers 1 Correct answer

Explorer , Nov 06, 2019 Nov 06, 2019

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 mad

...

Votes

Translate

Translate
Community Expert ,
Nov 05, 2019 Nov 05, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 05, 2019 Nov 05, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Nov 05, 2019 Nov 05, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 05, 2019 Nov 05, 2019

Copy link to clipboard

Copied

Thats a nifty idea! the answer had eluded me for over a week now! just couldnt wrap my head around it. Thanks heaps!

 

Based on that, i didnt even need to create a hidden field, just use one of the headings already on the page. Took some calculation trials but seem to have it working nicely for this set. Will see how it goes further along the document but should be great.

 

This is what i did as in my test document for the odd numbers

var VH = this.getField("VV1 - Head").page;
var VVA = event.target.page;

event.value = "4." + ((VVA - VH) * 2);

this.calculateNow();


and this calculationg for the second section on the page (even numbers)

var aName = event.target.name.split(".");
aName.pop();
var prefix = aName.join(".");

var VH = this.getField(prefix + ".VVA1 - Head Test").value;

event.value = (VH + 0.1);

this.calculateNow();

 

I tried to just to basic calc for the even numbers but the calculation was irritating me haha.

 

Thanks again!

 

Votes

Translate

Translate

Report

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
Explorer ,
Nov 05, 2019 Nov 05, 2019

Copy link to clipboard

Copied

I am such an idiot! hahaha

 

did this for the even numbers just now... only just clicked to put it all in brackets and plus 1! 😛 my brain is too far fried from all the script in this document!

 

var VH = this.getField("VV1 - Head").page;
var VVA = event.target.page;

event.value = "4." + (((VVA - VH) * 2) + 1);

this.calculateNow();


 

Votes

Translate

Translate

Report

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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Copy link to clipboard

Copied

Hi Try67,

 

I need to throw a spanner in the mix.

 

This solution worked perfectly up until i made the reference page a template. The calculation no longer works as I think it is getting confused as there is more than one field with that name (even if the original template is hidden). I am not renaming the fields on the template as i have alot of calculations on there and only one page of it is to be made. from that template there is a button to add the new templates for calibrations/validations just like before.

 

Do you have any suggestions on how I could get it to work. the calculations only shows up as NaN. no errors in the console as it can find the field just find, just that there are technically 2 of them

Votes

Translate

Translate

Report

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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Copy link to clipboard

Copied

I should mention i tried to run a this.addField on the page to use as a reference point, but it seems you cant add fields to spawned pages. 

Votes

Translate

Translate

Report

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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Copy link to clipboard

Copied

LATEST

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.

 

 

Votes

Translate

Translate

Report

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