Copy link to clipboard
Copied
I have a form at work that I am trying to setup so that it will import data from a text file.
I have got it to work in Adobe Acrobat PRO (Continuous Release | Version 2024.003.20112 | 64-bit).
Unfortunately, it does not work in Adobe Acrobat Reader (Continuous Release | Version 2024.003.20112 | 64-bit).
I have placed the trusted function in the user folder. I used " app.getPath('user','javascript')" in the console to find the correct location.
My question is, can Adobe Acrobat Reader do this and if it can, could someone please check the code below to advise me what I am doing wrong. If reader can't do it, so be it.
Code placed in the user folder
//Code from Adobe Acrobat Community Post "Run "importTextData" on a form button", reply posted by Bernd Alheit, Community Expert, May 22, 2019
var myImportTextData = app.trustedFunction(function(cPath)
{
app.beginPriv();
this.importTextData(cPath);
app.endPriv();
});
Code placed in the text field of the form. Action - On Focus.
myImportTextData("/C/Users/*******/Desktop/Import Text/AmbTherm.txt");
I also would like to send a big thank you to (in no particular order), Bernd Alheit (thanks for the code above), Karl Heinz Kremer, TRY67 and Nesa Nurani.
When I started early this year, I had absolutely no idea about javascript (or Acrobat at all). While every one on this forum has taught me something, the four of you have had the greatest impact, so THANK YOU.
Copy link to clipboard
Copied
If you look at the entry for the "importTextData()" function in the Acrobat JavaScript reference you'll see a block at the top of the entry that lists "rights" for the function.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#importtextdata
The last entry is labeled "Product" and it has a value of "F". This indicates that Form Rights are required for this function to operate in Reader. So the official line is NO. That said, Adobe has allowed some functions that require this right to operate in Reader, but it looks like this is probably not one of them. However, you can apply Form Rights to your form in Acrobat Pro from the "File > Save as Other > Reader Extended PDF" menu item.
But it does get slightly more complicated. There are actually several different types of "Form Rights", and the entry in the Rights bar doesn't provide any detail. So saving as a Reader Extended PDF may or may not work for getting this function to operate in Reader.
Copy link to clipboard
Copied
Unfortunately it won't work with a Reader Extended PDF. When testing in Reader, if you select "Show console errors and messages" under Preferences (Ctrl + k) > JavaScript > JavaScript Debugger, the console will appear displaying the security error when you try to execute the function. For testing in Reader you could also create a button with the following Mouse Up action: console.show() to open the console and run scripts. In this case you wouldn't run the trusted function, only what's inside it. Code run from the console is itself privileged.
Copy link to clipboard
Copied
There actually is a solution to this issue. Just not using the importTextData function. Instead, use the "util.readFileIntoStream()" function. You will have to write your own code for parsing the data and loading it into the PDF.
You'll find some info on this process here:
https://www.pdfscripting.com/public/Form-Data-Handling.cfm
And here is a tool that does exactly what you want:
https://www.pdfscripting.com/public/Select-and-Load-Form-Data-Tool-Description.cfm
It works in Reader, but is only available to site members.
Copy link to clipboard
Copied
If you look at the entry for the "importTextData()" function in the Acrobat JavaScript reference you'll see a block at the top of the entry that lists "rights" for the function.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#importtextdata
The last entry is labeled "Product" and it has a value of "F". This indicates that Form Rights are required for this function to operate in Reader. So the official line is NO. That said, Adobe has allowed some functions that require this right to operate in Reader, but it looks like this is probably not one of them. However, you can apply Form Rights to your form in Acrobat Pro from the "File > Save as Other > Reader Extended PDF" menu item.
But it does get slightly more complicated. There are actually several different types of "Form Rights", and the entry in the Rights bar doesn't provide any detail. So saving as a Reader Extended PDF may or may not work for getting this function to operate in Reader.
Copy link to clipboard
Copied
Thanks Thom, I'll try that tomorrow when I'm back at work.
My apologies, you are another poster who has helped me a lot on my educational journey with acrobat and I forgot to acknowledge in you in my post above, so thank.you for your help over the year.
Copy link to clipboard
Copied
Unfortunately it won't work with a Reader Extended PDF. When testing in Reader, if you select "Show console errors and messages" under Preferences (Ctrl + k) > JavaScript > JavaScript Debugger, the console will appear displaying the security error when you try to execute the function. For testing in Reader you could also create a button with the following Mouse Up action: console.show() to open the console and run scripts. In this case you wouldn't run the trusted function, only what's inside it. Code run from the console is itself privileged.
Copy link to clipboard
Copied
You were right (as usual). Another person I forgot to thank in my original post, no doubt there are heaps more.
I tried the cosole in reader and got the security error. I will just have to live with it as there is no chance of everyone getting updated to Acrobat.
I do have another question about number formatting but I will have more of a play with before I post it (It will be a neew post, I promise.
Again thaks to you and Thom for helping.
Copy link to clipboard
Copied
Unforetunately, that did not so I will have to just update our forms every time there is any change to the data.
Thaks for your help.
Copy link to clipboard
Copied
I really need to proofread before posting. The number of my typos and bad spelling is really bad.
Copy link to clipboard
Copied
It happens to all of us. Do you know you can edit your post by clicking the 3 dots to the left of the word More?
Copy link to clipboard
Copied
I did not know that. I can't see the word more or 3 dots anywhere on this page.
Are the posts locked if someone has replied to it?
Copy link to clipboard
Copied
No
Copy link to clipboard
Copied
Thanks. I'll just have to be more careful before I click the post icon.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It is not available for new users.
Copy link to clipboard
Copied
There actually is a solution to this issue. Just not using the importTextData function. Instead, use the "util.readFileIntoStream()" function. You will have to write your own code for parsing the data and loading it into the PDF.
You'll find some info on this process here:
https://www.pdfscripting.com/public/Form-Data-Handling.cfm
And here is a tool that does exactly what you want:
https://www.pdfscripting.com/public/Select-and-Load-Form-Data-Tool-Description.cfm
It works in Reader, but is only available to site members.
Copy link to clipboard
Copied
Thanks Thom, I'll have a look at the "util.readFileIntoStreeam()" function.
Unfortunately, I'll have to put the idea on hold for a while as I've been tasked to work on another form.
I doubt I would get permission to purchase your tool mentioned above unfortunately as it would make my work life a lot easier. If by some miracle, I do get permission, is this tool something I can add my self to Acrobat or would I have to go through our I.T department to do.
Copy link to clipboard
Copied
You can add it yourself. It doesn't require admin permissions, because it installs into your user area.
Copy link to clipboard
Copied
Thanks Thom Parker, you are a absolute legend. I finally had a chance to have a go at the "util.readFileIntoStreeam()" function. It works like a charm. This is going to greatly reduce my future work load. I wouldn't have thought to use this if you hadn't of mentioned it.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more