Beenden
  • Globale Community
    • Sprache:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Run "importTextData" on a form button

Neu hier ,
May 21, 2019 May 21, 2019

Hello!
I've been making a PDF-form to make invoices. And to make it a bit easier when filling my customers data, I did a spreadsheet with the data and saved it as "Tab Delimited Text" file. The import works fine but when I try to add a button called "Customer List" and run JavaScript to trigger the pop-up to choose which data I want imported, the pop-up won't trigger.

Oddly enough though, when I open the JavaScript console and press the Enter key on my numpad, the pop-up gets then triggered (as shown below)

Obviously I'm missing something to make it work, and I'll be very thankful for any help or if you could point me to the right direction where to learn this since my JavaScript knowledge is very limited! Thanks in advance!

importdataText.png

THEMEN
PDF Forms
3.7K
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 21, 2019 May 21, 2019

From the documentation of this method:

Note: (Acrobat 8.0) If cPath is specified, this method can only be executed during batch and console

events. See Privileged versus non-privileged context for details. The event object contains a

discussion of JavaScript events.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 21, 2019 May 21, 2019

Ok, I see.
Do you have any suggestions on an alternative? Because the "import form data" function only lets me import .fdf-files.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 21, 2019 May 21, 2019

This doesn't mean you can't use it, you just have to go about it differently.

To provide the code a "privileged context" you can, for example, call it from a .js file that's installed in the application's JavaScripts folder, and then it should work. See: https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 21, 2019 May 21, 2019

Ah ok!

I read the tutorial, but I don't seem to understand how to fix this "privilege" issued when running the JavaScript code.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 21, 2019 May 21, 2019

I've tried giving the code "privileged context" in a file "config.js" that I created. And it's placed in the Javacscripts folder on my "user" path. Yet I don't seem to make it work. I'm really new to JavaScripting, so I'll be glad if i could get some help!

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
LEGENDE ,
May 22, 2019 May 22, 2019

You're headed the right way. Did you create a trusted function? Do you get any errors in the console? What code did you add?

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 22, 2019 May 22, 2019

I get a "NotAllowedError". And this is the code that I used.

var ImportTextData = app.trustedFunction(function(cPath)

{

    app.beginPriv();

    this.importTextData("/c/user/data/customer_data.txt", cPath);

    app.endPriv();

});

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 22, 2019 May 22, 2019

You either pass the path to the text file as a parameter, or you hard-code it into the code.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 22, 2019 May 22, 2019

Where does you place the code?

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 22, 2019 May 22, 2019

On a config.js-file in the "user" javascripts folder path

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 22, 2019 May 22, 2019

stefano.bianque  schrieb

On a config.js-file in the "user" javascripts folder path

In following path?

C:\Users\<user>\AppData\Roaming\Adobe\Acrobat\Privileged\DC\Javascripts

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 22, 2019 May 22, 2019

https://forums.adobe.com/people/Bernd+Alheit  skrev

stefano.bianque   schrieb

On a config.js-file in the "user" javascripts folder path

In following path?

C:\Users\<user>\AppData\Roaming\Adobe\Acrobat\Privileged\DC\Javascripts

Exactly on that path. Also it should be noted, that the folder didn't exist in my directory so I have to manually create it.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
LEGENDE ,
May 22, 2019 May 22, 2019

When do you get the message? When config.js is loaded (Acrobat startup)? Or when you call the function? What is your function call and how do you call it?

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 22, 2019 May 22, 2019

https://forums.adobe.com/people/Test+Screen+Name  wrote

When do you get the message? When config.js is loaded (Acrobat startup)? Or when you call the function? What is your function call and how do you call it?

I get the "NotAllowedError" when I start Adobe and when I call the function in the PDF-form button I made. And the code I put was:

this.ImportTextData("/c/user/data/customer_data.txt");

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 22, 2019 May 22, 2019

Try this:

var myImportTextData = app.trustedFunction(function(cPath)

{

    app.beginPriv();

    this.importTextData(cPath);

    app.endPriv();

});

myImportTextData("/c/user/data/customer_data.txt");

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
LEGENDE ,
May 22, 2019 May 22, 2019

You will always get the error if you code this.ImportTextData. Adding your startup script cannot change that. You must actually use the function that you created. This is complicated stuff but you do need to read and understand the instructions. So, let's focus on that. Please try to follow them, and if anything doesn't make sense, ask us about that. When you have a full understanding, you will be ready to write the script.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
May 22, 2019 May 22, 2019

I've been reading these guides here:
Using Trusted Functions

https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf

yet, I fail to see how I'm supposed to implement the "ImportDataText" function. My JavaScript-knowledge is non-existent, so yes, it doesn't make any sense right now.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
May 22, 2019 May 22, 2019
AKTUELL

The function you're defining does not become a method of the Document object (to which "this" refers to). It's an independent function.

Also, I highly recommend you change the name from ImportTextData to something else, as that is very similar to the built-in function's name and can cause confusion. Call my something like "myImportTextData", or "trustedImportTextData", or something like that (just like in Bernd's code above).

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
LEGENDE ,
May 22, 2019 May 22, 2019

We can't tell you everything about JavaScript in a few replies, so if you want to do this task focus on the guide. Please start at the beginning of Using Trusted Functions . Read through it carefully and stop at the first thing you do not fully understand. DO NOT SKIP ANYTHING, this is why your solutions are not working. Once you understand that point we can move to the second point, and so on. BEFORE you can understand this you have to know what a function is in JavaScript, so if you don't know that please say.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines