Copy link to clipboard
Copied
Background: I have a PDF for reporting purposes where the second page repeats as many times as needed.
The number of repetition however is always different depending on the case.
I was successful in spawning a page from a template through a button with this code
var a = this.getTemplate ("template");
a.spawn();
However when I press the button the previously filed out page is basically being duplicated and fields are already filled out.
How can I reset all fields except for one certain field when clicking the spawn button?
Don't know if this should be another topic:
How can I make a sum of a certain field that repeats on every spawned page?
I know that the spawned field names are:
Pnn.template.fieldname
How can I make a sum of a fieldname that appears on every spawned page but with a unique Pnn Prefix?
Thanks a lot in advance for anyone taking the time to answer this.
With your script, the fields should not be filled in. You are using the default parameters to Template.spawn(), which means that bRename is set to "true" - which means that all fields will be renamed (see here for more information about the parameters: Acrobat DC SDK Documentation ).
Is it possible that the fields you are filling out are on a template page that is not hidden when you load the document? In this case, you are actually modifying the template page before it gets spawned, so you end u
...Copy link to clipboard
Copied
With your script, the fields should not be filled in. You are using the default parameters to Template.spawn(), which means that bRename is set to "true" - which means that all fields will be renamed (see here for more information about the parameters: Acrobat DC SDK Documentation ).
Is it possible that the fields you are filling out are on a template page that is not hidden when you load the document? In this case, you are actually modifying the template page before it gets spawned, so you end up with a copy of the state of the page at the time you spawn a new instance of that page. The solution to this is to hide your page template and use a script to spawn the first instance of the page as well. This way, you will always start out with a blank page.
As to your second question: Your summary field needs to find out it's own name, and then based on that name determine in what group it is in (e.g. the Pnn.template part of the name). You then use that part to create your field names for the fields you want to sum up.
Copy link to clipboard
Copied
Oh damn, that was it! Thanks a lot for your answer!
Copy link to clipboard
Copied
Now I am running into another error which makes sense:
I have calculations on the template page field3 = field1+field2 as the prefixes and suffixes of the fieldnames are changing the calculations are broken.
How can I fetch the current page I am on from the Pnn.fieldname.template of the spawned page field structure so that the calculation does not get lost when spawning a new page? thx a lot in advance!
Copy link to clipboard
Copied
Use something like this as your calculation script:
// get this fields name
var fieldName = event.target.name;
// strip off the last part of the name
var groupName = fieldName.substring(0, fieldName.lastIndexOf(".")+1);
// calculate the sum
event.value = this.getField(groupName + "Field1").value + this.getField(groupName + "Field2").value;