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

Duplicate a locked page and make it fillable

Community Beginner ,
Dec 05, 2018 Dec 05, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

348

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

Community Expert , Dec 05, 2018 Dec 05, 2018

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

...

Votes

Translate

Translate
Community Expert ,
Dec 05, 2018 Dec 05, 2018

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?

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 Beginner ,
Dec 05, 2018 Dec 05, 2018

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.

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 ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Did you tell the Template object to rename the fields on the spawned 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
Community Beginner ,
Dec 05, 2018 Dec 05, 2018

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;

}}

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 ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

LATEST

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.

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