Rights to open a dialog for selecting a file

Community Beginner ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

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.

TOPICS
JavaScript , PDF forms

Views

211

Likes

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
LEGEND ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

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

Likes

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

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.

Likes

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
Adobe Community Professional ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

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

Likes

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

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.

Likes

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
Adobe Community Professional ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

Why do you do it in your code in the first place? Just set it in Acrobat and save the file, and remove that line from your code.

Likes

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

Sorry but I do not understand..

Likes

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
Adobe Community Professional ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

Why did you include this line in your code? Why not set this setting it once and that's it?

Are you using this field for regular text at any point, or only for file selection?

Likes

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

This field is hidden and is for file selection only.
Please write directly what to delete and what and where to move.

Likes

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
Adobe Community Professional ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

Delete this line of code:

fld.fileSelect = true; 

Likes

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

How do I change this parameter permanently?
In the form editor (text box properties) this option cannot be accessed, it is displayed but cannot be changed.
If it is possible, please write how to do it.

Likes

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
Adobe Community Professional ,
May 26, 2022 May 26, 2022

Copy link to clipboard

Copied

Execute following in the Javascript console of Adobe Acrobat and save the document:

var fld= this.getField("Plik"); fld.fileSelect = true;

Likes

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
Adobe Community Professional ,
May 26, 2022 May 26, 2022

Copy link to clipboard

Copied

You have to tick "Scroll Long Text" (and nothing else!) and then this option will become available:

 

try67_0-1653553311877.png

 

Likes

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 ,
May 26, 2022 May 26, 2022

Copy link to clipboard

Copied

I do not see the logic in how to get to this setting ... but OK, this step is done.
Unfortunately, the problems continue.
I have moved the import fields to the main form and they are hidden. (This is to avoid the need for Reader to create a TMP document.) As well as a field for storing the path to a file. Everything works perfectly but ... again only in the DC Pro.
When you try to import from Reader, a dialog opens to select a file (that's something, it didn't work before!), Points to the file and crashes on line 10 with the definition of a variable for saving the error code (err = this.importTextData (dataFile, idx);).

var fld= this.getField("Plik");
fld.browseForFileToSubmit(); 
var dataFile = fld.value; 

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

while (err==0){
	err=this.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= this.getField("PoleA").value;
		var PoleB= this.getField("PoleB").value;
		var PoleC= this.getField("PoleC").value;
		var PoleD= this.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++
}

Likes

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
Adobe Community Professional ,
May 26, 2022 May 26, 2022

Copy link to clipboard

Copied

You can use importTextData in Acrobat Reader when the document has form rights.

Likes

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 ,
May 30, 2022 May 30, 2022

Copy link to clipboard

Copied

quote

You can use importTextData in Acrobat Reader when the document has form rights.


By @Bernd Alheit

Can you explain it? I don't see a similar rights option anywhere in the document properties. What to set up for the form with the script quoted above to work properly in Reader.

Likes

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
LEGEND ,
May 30, 2022 May 30, 2022

Copy link to clipboard

Copied

This right can be added using Adobe Experience Manager - not Acrobat. Licensing for Adobe Experience Manager (AEM) and price are by negotiation, but expect a 5-6 figure annual fee.

Likes

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 ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

This is illogical ..... I pay for a PDF editing and form building tool that I cannot use in Adobe Reader later, and to set up some additional option that allows me to do it, I have to spend another lot of money ...

Summarizing, please correct me if I make a mistake, it is not possible to create a form with the possibility of importing data by Java script using Adobe Pro DC, which I will be able to fill in using Adobe Reader? If I still understand correctly, I can do it, but to handle such a form, the person filling it out must also have the Adobe Pro DC tool.

Likes

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
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

You pay for the right to edit a PDF file, and you have that right, but that doesn't give someone who didn't pay anything (a Reader-user) a similar right... If you want to extend your advanced rights to them, you have to pay extra for it. I think that makes total sense, but you might disagree.

And yes, they will need to have either that right or Adobe Acrobat (either Pro or Standard), to be able to import a text file into the PDF.

However, there are ways around it, but it will require a more complex script.

A script can be used to read a text file, parse it and then use the data from it to populate text fields, even without this special right. Another option is to have the user copy the text data and then paste it into a window (or even a field), and parse it from there. All of this can be done using the free Reader, without any special rights. I've developed similar tools in the past so if you're interested in purchasing such a tool feel free to contact me privately to discuss it further.

Likes

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 ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

In this example, I am using this approach because I found outright that this is the only import option.

However, if it is possible to open a text file directly and analyze it with text functions, it's perfect !! In fact, this is the kind of knowledge I am looking for.

I will be grateful for any example, e.g. a working form that I can analyze myself.

The general assumption of my work is to create a form in which I will allow you to enter data from a finger or import from a text file, analyze this data and finally print or save an electronic version with the possibility of electronic signature. These forms MUST be handled by free applications afterwards.
For example, now I will be creating a vehicle registration form for transport companies (e.g. for taxi corporations). There are tables containing a lot of detailed data (registration numbers, VIN numbers, brand, model, etc.), that is data that every entrepreneur has in some system. It would be foolish to require you to enter all this data manually, sometimes for several dozen or several hundred vehicles. The import option is actually the only one that makes sense.

Likes

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 ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

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

Likes

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
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

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

Likes

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 ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

Ok, this way from util.readFileIntoStream works very nicely, actually in 3 lines of code I get the content of the text file. The rest is string support.
Unfortunately, there is a permission problem in Reader again.
As described in the manual
"this method can only be executed in privileged context, during a batch or console event (or when the document is certified with a certificate trusted to execute" embedded high privileged JavaScript ")".

The task facing the form (in my case) excludes the need to set trusted certificates in the program settings. The citizen simply has to download the form from the website of the city hall, fill it in and send it to the office. As you can see, the use of other than open source software by citizens is also omitted here.
The form will of course be signed electronically at the office by the appropriate person.
Can anyone tell me if it is possible with the main assumption that the citizen only uses Reader? What Adobe package do I need to prepare such a form is a separate matter. At the moment it is Adobe Pro DC, of ​​course I do not want to change it if I do not have to (as in public offices :-))

Likes

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
Adobe Community Professional ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

If you can't put it in a trusted function then no, you can't specify the file path. You can still use it, though, but the user will have to select the text file manually.

Likes

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 ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

LATEST

Indeed, I expect the user to point to this file.

Yes, you are right, when I delete the path to the file in the script code, Reader shows the file selection dialog and after selecting the correct file, it reads the content.
The funniest thing is that I did it before, but I ran the test with the path entered hard and I did not notice that when choosing Reader it behaves differently and does not report a problem with permissions.

Turns out I finally have a solution.
Thank you very much 😉

Likes

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