Skip to main content
Participant
October 10, 2018
Answered

How to use a botton event import some string from txt to text field

  • October 10, 2018
  • 2 replies
  • 799 views

dears,

I have add a botton in acrobat,it‘s javascript code as follow.

this.importDataObject("myData.txt");

var oFile = this.getDataObjectContents("myData.txt");

var cFile = util.stringFromStream(oFile,"GBK");

aFile = cFile.split(";");

this.getField("text0").value = aFile[0];

if (aFile[1] == "1"){

this.getField("text4").value = "Yes";

this.getField("text1").value = aFile[2];

this.getField("text3").value = aFile[3];

this.getField("text4").value = aFile[4];

}

if (aFile[1] == "0"){

this.getField("text5").value = "Yes";

this.getField("text2").value = aFile[2];

this.getField("text5").value = aFile[3];

this.getField("text6").value = aFile[4];

}

Open this with acrobat editer,it works. This fuction will open a dailog,then we can select the txt file,and then the text field will fill up.

but when i open this with acrobat reader,it cann't works. I don't kown how adjust my code,then it can be work in acrobat reader.

please help me,I would appreciate it very much.thanks.

This topic has been closed for replies.
Correct answer uintonq74382773

Thank you for your Suggestions, i have change my code.

var oFile = util.readFileIntoStream();

var cFile = util.stringFromStream(oFile,"GBK");

aFile = cFile.split(";");

this.getField("text0").value = aFile[0];

if (aFile[1] == "1"){

this.getField("text4").value = "Yes";

this.getField("text1").value = aFile[2];

this.getField("text3").value = aFile[3];

this.getField("text4").value = aFile[4];

}

if (aFile[1] == "0"){

this.getField("text5").value = "Yes";

this.getField("text2").value = aFile[2];

this.getField("text5").value = aFile[3];

this.getField("text6").value = aFile[4];

}

It can be  work in adobe reader.

Thanks for your help again@

2 replies

uintonq74382773AuthorCorrect answer
Participant
November 29, 2018

Thank you for your Suggestions, i have change my code.

var oFile = util.readFileIntoStream();

var cFile = util.stringFromStream(oFile,"GBK");

aFile = cFile.split(";");

this.getField("text0").value = aFile[0];

if (aFile[1] == "1"){

this.getField("text4").value = "Yes";

this.getField("text1").value = aFile[2];

this.getField("text3").value = aFile[3];

this.getField("text4").value = aFile[4];

}

if (aFile[1] == "0"){

this.getField("text5").value = "Yes";

this.getField("text2").value = aFile[2];

this.getField("text5").value = aFile[3];

this.getField("text6").value = aFile[4];

}

It can be  work in adobe reader.

Thanks for your help again@

Bernd Alheit
Community Expert
Community Expert
October 10, 2018

Any error message in the console?

Participant
October 10, 2018

thanks for your reply.  Yes,the message as follow

NotAllowedError:Security Settings prevent access to this property or method

Doc.importDataObject:1

Bernd Alheit
Community Expert
Community Expert
October 10, 2018

Looks like not allowed in Acrobat Reader.