Copy link to clipboard
Copied
Hello,
I have a PDF form with 33 pages. I want it to work this way:
- Every time you fill in the fields of a page, you click on a button to lock that page, and then you move on to the next one.
- Sometimes, when you have a specific value entered on the text fields, you click on a button in order to duplicate the page that is already locked and re-enter the needed information. (The button duplicates the page and unlocks its text fields).
- A page can be duplicated as many times as needed, and everytime you need to be able to fill in the text fields.
By using Javascript, I was able to do all of the above, except of one thing: Once my page is duplicated (using a Template), I cannot predict the name of the new page, thus making it impossible for me to unlock the fields that were already locked on the Template.
I wanted to use a For Loop in order to do this, but I am not sure how to insert a variable in the instruction. I tried this but it did not work:
var k;
for (k = 0; k < 1000; k++)
{
this.getField("P"+k+".Page4.Text1").readonly = false;
}
Do you have any ideas on how to make it work properly?
Thank you.
OK. I think the problem is you're spawning the page after the current one.
That means you can end up with pages that have the same field names, even
though you told the spawn method to rename them. The name of the fields
includes the template name, the page number of the new spawned page and the
original field name.
Let's say you have a template called T1 on page 1 with field called
"Text1". You spawn it once as page 2. The name of the field on the new page
is "P1.T1.Text1". Now you spawn the original
...Copy link to clipboard
Copied
Your code is correct, and the names of the fields on pages spawned by a Template object are predictable, so it should be possible...
What happens when you try to run it, exactly?
Copy link to clipboard
Copied
Thank you for your fast response.
When I run the code, my page is spawned correctly but all the fields are locked.
Copy link to clipboard
Copied
Did you tell the Template object to rename the fields on the spawned page?
Copy link to clipboard
Copied
This is the code I am using:
if( app.alert({
cMsg: "Do you want to duplicate this page?",
cTitle: "Duplicate Form Warning",
nIcon: 2,
nType: 2
}) == 4) {
var expTplt = getTemplate("Page4");
expTplt.spawn({
nPage:this.pageNum+1,
bRename:true,
bOverlay:false
});
var k;
for (k = 0; k < 1000; k++)
{
this.getField("P"+k+".Page4.Text169").readonly = false;
}}
Copy link to clipboard
Copied
OK. I think the problem is you're spawning the page after the current one.
That means you can end up with pages that have the same field names, even
though you told the spawn method to rename them. The name of the fields
includes the template name, the page number of the new spawned page and the
original field name.
Let's say you have a template called T1 on page 1 with field called
"Text1". You spawn it once as page 2. The name of the field on the new page
is "P1.T1.Text1". Now you spawn the original template again, also as page
2. The name of the field on that page will also be "P1.T1.Text1", so it's
a duplicate of the field that you spawned before, which is now on page 3.
The solution is to always spawn new pages at the end of the document, to
make sure they have unique names. If you want you can them move that page
to a different location, although that also complicates things... In short,
this is not a trivial task at all, probably one of the more complex ones
there is in PDF files.