Skip to main content
Participant
March 26, 2025
Question

Clearing text and checkboxes on spawned PDF page

  • March 26, 2025
  • 2 replies
  • 307 views

Hi,


I have a PDF document that I've created which has a large number of text and check boxes on what will start out as a single page.


My ultimate aim is to be able to click a button and have the same page spawned, but with all the text boxes cleared of any text, and all the checkboxes unclicked. It should not affect the other page(s).


I have tried:


**Attempt 1**


Creating a template page with cleared textboxes / checkboxes. I could then add the following Javascript to a 'new page' object, before then hiding the template page so it was always blank:


var newPage = this.spawnPageFromTemplate({
cTemplate: this.getNthTemplate(0),
bRename: true,
bOverlay: false
});


For some reason this doesn't create all the textboxes on the new page, so I had to abandon this approach.


**Attempt 2**


Keeping the first page as the template page and keeping it unhidden.
When using the same code above, this now ensures that all text boxes are created for some reason.


However, when the user populates the first page and then spawns another, it will copy whatever text / checkboxes that they put into the first page.

I therefore need to add code that removes all of the text boxes / clicked checkboxes, but ONLY for the newly created page (not any others).


I tried the following code, but I am well out of my depth here.


var newPage = this.spawnPageFromTemplate({
cTemplate: this.getNthTemplate(0),
bRename: true,
bOverlay: false
});


// Get the page's field names and reset based on the prefix
var aNameParts = event.targetName.split(".");
var strPrefix = aNameParts[0] + "." + aNameParts[1];
this.resetForm(strPrefix);


It doesn't work...

Does anyone have any ideas as to how I could get this to work?


Thanks in advance

2 replies

JR Boulay
Community Expert
Community Expert
March 29, 2025

[MOVED TO THE ACROBAT DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
March 26, 2025

- Use a hidden page as the Template, instead of a visible one. That way, you won't have to clear any values when you spawn a copy from it.

- Do not use the spawnPageFromTemplate method. It was deprecated and replaced by the spawn method of the Template object itself.

Participant
March 26, 2025

Thanks for getting back to me.

I updated the code to the following, after hiding the template page:

var template = this.getTemplate("T1");

var newPage = template.spawn(0, true, false);

Unfortunately it doesn't seem to copy all of the text boxes (as was the case in my first attempt when I had the template hidden). An additional issue pops up when I try this approach in that the checkboxes seem to all be synced across pages even though (I think) I've put the 'rename' setting to TRUE.

Do you have any idea as to what coudl be causing this?

Thanks again.

try67
Community Expert
Community Expert
March 26, 2025

No... I'll need to see the file first.