Assist in button to import data from either a txt file or attached txt file to pdf?

New Here ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

I'm very new to this community and have no idea where to start on this. I have a text document exported from excel with data propperly named and formated. Testing it by importing it manualy through "prepare from" works perfectly, I was just curious if there was any way to make a button that will (upon being pressed) update the data if there has been any changes? I'm willing to use javascript, or if there is another solution that would also be great. Thank you in advance for any advice on the matter. 

TOPICS
Create PDFs, How to, JavaScript, PDF forms

Views

125

Likes

translate

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
Most Valuable Participant ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Yes, it's possible, but with one caveat. If you want to specify the path of the file to import then the script has to run from a trusted context, such as a folder-level script file. Otherwise you'll be prompted to select the file each time you click the button. If you're OK with that all you need is the following code:

 

this.importTextData();

Likes

translate

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
New Here ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Thank you for the reply, this works perfectly for what I need.

 

I did see you mention that any other way would need to run from a trusted context, how would I go about that for this type of situation? While I will be using the java you provided, maybe I can use the other method for a different document.

Likes

translate

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
Most Valuable Participant ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

I recommend reading these tutorials on the subject:

https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts

https://acrobatusers.com/tutorials/using_trusted_functions

 

Basically you would need to write a trusted function and place it in a .js file that's located in a specific folder on each computer. Then the button could call that function, passing the path of the text file to it as a parameter and it would import the data from it directly.

Likes

translate

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