Skip to main content
Participating Frequently
March 7, 2018
Answered

Spawn page from template with partially resetted fields

  • March 7, 2018
  • 1 reply
  • 1554 views

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.

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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.

1 reply

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
March 7, 2018

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.

frejmAuthor
Participating Frequently
March 7, 2018

Oh damn, that was it! Thanks a lot for your answer!