Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

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

Community Beginner ,
Dec 04, 2024 Dec 04, 2024

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.

TOPICS
JavaScript
2.1K
Translate
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
3 ACCEPTED SOLUTIONS
Community Expert ,
Dec 05, 2024 Dec 05, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 Expert ,
Dec 05, 2024 Dec 05, 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.

View solution in original post

Translate
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 Expert ,
Dec 06, 2024 Dec 06, 2024

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. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 Expert ,
Dec 05, 2024 Dec 05, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Dec 05, 2024 Dec 05, 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.

Translate
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 Expert ,
Dec 05, 2024 Dec 05, 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.

Translate
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 ,
Dec 05, 2024 Dec 05, 2024

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.

Translate
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 ,
Dec 05, 2024 Dec 05, 2024

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.

Translate
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 ,
Dec 05, 2024 Dec 05, 2024

I really need to proofread before posting. The number of my typos and bad spelling is really bad.

Translate
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 Expert ,
Dec 05, 2024 Dec 05, 2024

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?

Translate
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 ,
Dec 05, 2024 Dec 05, 2024

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?

Translate
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 Expert ,
Dec 05, 2024 Dec 05, 2024

No 

Translate
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 ,
Dec 06, 2024 Dec 06, 2024

Thanks. I'll just have to be more careful before I click the post icon.

Translate
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 Expert ,
Dec 06, 2024 Dec 06, 2024

PDFAutomationStation_0-1733488140836.png

 

Translate
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 Expert ,
Dec 06, 2024 Dec 06, 2024

It is not available for new users.

Translate
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 Expert ,
Dec 06, 2024 Dec 06, 2024

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. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Dec 06, 2024 Dec 06, 2024

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.

Translate
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 Expert ,
Dec 07, 2024 Dec 07, 2024

You can add it yourself.  It doesn't require admin permissions, because it installs into your user area. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Jan 01, 2025 Jan 01, 2025
LATEST

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.

Translate
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