Skip to main content
Known Participant
December 5, 2024
Answered

Trusted Function to import text does not work in Reader but does in Acrobat.

  • December 5, 2024
  • 1 reply
  • 1936 views

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.

Correct answer Thom Parker

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. 

 

1 reply

Thom Parker
Community Expert
Community Expert
December 5, 2024

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
December 5, 2024

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.

PDF Automation Station
Community Expert
Community Expert
December 5, 2024

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.