Skip to main content
Piotr Smolen
Inspiring
May 25, 2022
Question

Rights to open a dialog for selecting a file

  • May 25, 2022
  • 3 replies
  • 3927 views

I am forced to ask for help again.
I have a form with a button to import data from a text file. Here I am using the dialog to select a data file to be imported.
The form works as it should ... but only in Adobe Acrobat Pro DC. When I open it with Reder, the import function does not work.
Debugger shows error:

NotAllowedError: Security settings prevent access to this property or method.
Field.fileSelect: 46: Field Btn: Mouse Up

The line it crashes on is:
fld.fileSelect = true;

 

I think I've tried all possible security settings in Reader and can't find the reason.

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
May 31, 2022

You should read this about importTextData (pay attention to the red "Note"):

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/Acro12_MasterBook/JS_API_AcroJS/Doc_methods.htm?rhhlterm=importTextData&rhsyns=%20#XREF_92335_importTextData

 

And you should read this about the Availability (column 4):

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/index.html#t=Acro12_MasterBook%2FJS_API_AcroJSPreface%2FQuick_bars.htm&rhsearch=quick%20bar&rhhlterm=quick%20bar&rhsyns=%20

 

This will allow you to understand that it is a privileged context issue, not an activation of Reader issue (which is not required anymore since Acrobat Reader XI).

Acrobate du PDF, InDesigner et Photoshopographe
Piotr Smolen
Inspiring
May 31, 2022

Thank you, I will definitely do it very carefully. I had seen this document before, but I didn't know as much then as now.

Bernd Alheit
Community Expert
Community Expert
May 25, 2022

Acrobat Reader can change this property when the document has form rights.

Piotr Smolen
Inspiring
May 25, 2022

Ok, can I do it in DC Pro at the stage of development?
In the field properties I see this option but it's "gray" and I can't change it and that's strange to me.

try67
Community Expert
Community Expert
June 1, 2022

So, can I count on a hint on how to read the contents of a text file so that it is possible in Reader?


Read the documentation of the readFileIntoStream method of the util object in the Acrobat JS API Reference.

Legend
May 25, 2022

Please show the lines around this one in the script, looks as if the line number may be inaccurate. 

Piotr Smolen
Inspiring
May 25, 2022

I've read about Folder Level scripts, but this doesn't apply here. Namely, the forms are to be made available via the Internet to interested citizens and there is no question of any additional files in some folders and their rights.

 

Below is the entire code of the button handling the import. I would like to remember that in DC Pro it works as it should be.

 

var fld= this.getField("Plik");
fld.fileSelect = true; 
fld.browseForFileToSubmit(); 
var dataFile = fld.value; 
//tmpDoc1.closeDoc(true);

//var dataFile = "/D/Users/xxxxx/Documents/PDFy edytowalne/Test importu/dane.txt";
//var dataFile = "Dane.txt";

var tmpDoc = app.newDoc();

//tworzymy pola tymczasowe odpowiadające polom w dokumencie
tmpDoc.addField("PoleA", "text", 0, [0,0,100,100]); 
tmpDoc.addField("PoleB", "text", 0, [0,0,100,100]);
tmpDoc.addField("PoleC", "text", 0, [0,0,100,100]);
tmpDoc.addField("PoleD", "text", 0, [0,0,100,100]);

//definiujemy zmienne do pracy
var err =0;
var idx = 0;

while (err==0){
	err=tmpDoc.importTextData(dataFile, idx);
	if(err==-1)
		app.alert("Błąd: Nie mogę otworzyć pliku!");
	else if (err==-2)
		app.alert("Błąd: Nie mogę załadować danych!");
	else if (err==1)
		app.alert("Błąd: Brak danych!");
	else if (err==2)
		app.alert("Błąd: Użytkownik nie wybrał linii!");
	else if (err==3)
		app.alert("Błąd: Uzytkownik nie wybrał pliku!");
	else if (err==0){
		
		//pobieramy z pola w dokumencie tmpDoc
		var PoleA= tmpDoc.getField("PoleA").value;
		var PoleB= tmpDoc.getField("PoleB").value;
		var PoleC= tmpDoc.getField("PoleC").value;
		var PoleD= tmpDoc.getField("PoleD").value;
		
		//teraz przypisujemy wartości do właściwych pól w dokumencie
		this.getField("PoleA" + (idx +1)).value = PoleA;
		this.getField("PoleB" + (idx +1)).value = PoleB;
		this.getField("PoleC" + (idx +1)).value = PoleC;
		this.getField("PoleD" + (idx +1)).value = PoleD;
		
		if (idx==19){ //ta liczba w warunku jest o 1 mniejsza od liczby rekordów w pliku do importu
			err=-99;
		}
	}
	idx++
}
		
tmpDoc.closeDoc(true);

		

 

Above this code were comments that I removed. The second line in this listing is where Reader crashes.