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

Modify form field value in secured pdf documents

New Here ,
Nov 19, 2016 Nov 19, 2016

Hi,

I'm trying to modify the values of some form fields in a secured pdf document.

The code is located in a Folder level script. I have also tried to put the code inside a trustedFunction.

Some of the security settings in the document:

  • Password Security
  • Changing the Document: Not Allowed
  • Filling of form fields: Allowed
  • Signing: Allowed

The code is located in a "Folder level script". I have also tried to put the code inside a trustedFunction.

The code works fine in a non secured document:

var f = this.getField("nameOfField");

console.println("Old value= " + f.value);             // Prints the correct value

f.value = "New value";

console.println("New value = " + f.value);          // Prints the old value

No error message in the console.

Any help to guide me in the right direction will be greatly appreciated!

--Olav

TOPICS
Acrobat SDK and JavaScript , Windows
675
Translate
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
LEGEND ,
Nov 19, 2016 Nov 19, 2016

"Some of the security settings in the document:" probably is not providing the specific information that is needed.

The folder level code you provided throws errors when I start Acrobat. I do not believe that is the code you are calling in an attempt to change the field's value.

I get the following error upon opening Acrobat:

TypeError: this.getField is not a function

1:Folder-Level:User:DumbCode.js

because there is no open PDF form with the at least one form field. The "getField" method only exist when a PDF with form fields is open. If I  need to call a folder level block of code from within a PDF, I create a function that I can call as needed.

When you are "securing" the form, are you "locking" or somehow setting all the fields to "read only".

Translate
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
New Here ,
Nov 21, 2016 Nov 21, 2016

Thanks for your feedback!

The document comes from an external source. In addition I have created a simple document with only two fields and with the same security settings. In this case updating the fields works as expected.

In case you have the chance to look into the specific pdf document, you can find it here:

http://ec.europa.eu/DocsRoom/documents/15506/attachments/4/translations/en/renditions/native

I'm targeting to populate the fields under "5 National contact point information" on page 2 from an external file.

The code used for testing in the folder level script:

// Inserting a menu item in the help menu

try{app.addMenuItem({cName:"UpdateNcaInfo", cParent:"Help", cExec:"UpdateNcaInfo()" });}catch(e){}

var UpdateNcaInfo = app.trustedFunction(function()

{

     app.beginPriv();

     // Getting field through number

     var f = this.getField(this.getNthFieldName(41));

     console.println("field.name = " + f.name);

     console.println("field.value = " + f.value);

     console.println("------------------------------------");

    

     // Trying to set a new value

     f.value = "xxxxxxxxxxx";

     console.println("field.value = " + f.value);                                        // No success

     console.println("------------------------------------");

     // Getting the field object in the way I would expect it to be done:

     var f2 = this.getField("fsca.page2.SubmitterInfo.ncpOrgName");

     console.println("field.name = " + f2.name);

     console.println("field.value = " + f2.value);

     console.println("------------------------------------");

     // Trying again to set a new value

     f2.value = "yyyyyyyyyyyyyyyy";

     console.println("field.value = " + f2.value);                                        // No success

     console.println("------------------------------------");

     app.endPriv();

});

Any help to guide me in the right direction will be greatly appreciated!

Thanks!

--Olav

Translate
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
LEGEND ,
Nov 21, 2016 Nov 21, 2016
LATEST

Your form was crated with Adobe LiveCycle Designer not Acrobat. There is a separate forum for that product.

In entering data into the form there is at least one error causing JavaScript to fail.

Translate
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