Question Details

avatar
Welcome to the Acrobat Answers site. You're on your way! It won't take you many more points to reach the next level: Participant. And as you accumulate more points, you're also building your reputation with the community and with AcrobatUsers.com.

How do I create a path that util.readFileIntoStream will recognize?

I want to have a javascript that will run on a page open that checks for an xml data file. If found it will load data from that file. The PDF file and xml data file get created and put into a folder together. The xml data file is named the same as the PDF except the ".pdf" is replaced with "_Data.xml".

When I try to create the path to the data file the readFileIntoStream always fails.

If I don't include a path and let readFileIntoStream present an open file dialog, when I choose the file it works.

How do I get my constructed path to be recognized by readFileIntoStream?

Here is some of the code:

var fileName = this.documentFileName;
var filePath = this.path;
var dataFileName = "";
var dataFilePath = "";

dataFileName = fileName.replace(".pdf","_Data.xml");
dataFilePath = filePath.replace(fileName,dataFileName);

try{
dataStream = util.readFileIntoStream(dataFilePath);
}catch(e){
app.alert("Not found");
}


Peter Mitchell 701 days ago


3 Answers

Voted Best Answer

avatar
<p>Congratulations! The Acrobat User Community selection team has approved your status as Expert in the Acrobat User Community. We appreciate all your past contributions and hope you will continue to support the community by answering questions and participating in the Acrobat Answers Q&A program as you've done in the past.</p>

<p>As an expert, you will get a badge to display on your profile with the level EXPERT next to your name and you have become eligible to be nominated to the Adobe Community Professional Program.</p>

<p>After reviewing the Adobe Community Professional Program information at https://www.adobe.com/communities/professionals/, please let us know if you are interested.</p>

<p>Someone from the selection team will contact you soon regarding the community professional program. Keep up the good work!</p>

<p>Regards,</p>

<p>The Acrobat User Community Team</p>


<p>**** Disclosure Requirements for Endorsements Received by Third Parties  ****</p>

<p>If you endorse or refer people to the Acrobat User Community in any venue,  it is our responsibility to ensure that you are aware of required compliance with the <a href="http://ftc.gov/os/2009/10/091005revisedendorsementguides.pdf">FTC’s Guidelines</a>. Both you and Adobe can be held liable under federal law for making unsubstantiated claims and for not disclosing your relationship with Adobe. In particular:</p>

<ol>
<li>Always disclose if you have received any type of incentive – free products, promotional items, travel, gifts, payment, and so on from Adobe. The disclosure must be on the same page as the endorsement.</li>
<li>Be truthful. Endorsements should not be misleading. Never make unsubstantiated or exaggerated claims about the benefits of Adobe products or programs. Any statements or endorsements about an Adobe product must be based on upon your actual experience.</li>
</ol>

Thank you again for your support of Adobe and the Acrobat User Community</p>

Unless this document is used in a closed environment where you can install folder level scripts on everyone's system, you won't be able to use the util.readFileIntoStream() function. A better method is to attach the XML file to the PDF, then use the Doc.getDataObjectContents() fucntion to read the data. The data travels with the PDF and script will work anywhere, including on Reader.

Thom Parker
The source for PDF Scripting Info pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often

The most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)

Having trouble, Why Doesn't my Script Work


By Thom Parker answered 701 days ago  |   Comments (0)  |  New Comment

avatar

  |   Report
Was this answer helpful?  
1
0

avatar
<p>Congratulations! The Acrobat User Community selection team has approved your status as Expert in the Acrobat User Community. We appreciate all your past contributions and hope you will continue to support the community by answering questions and participating in the Acrobat Answers Q&A program as you've done in the past.</p>

<p>As an expert, you will get a badge to display on your profile with the level EXPERT next to your name and you have become eligible to be nominated to the Adobe Community Professional Program.</p>

<p>After reviewing the Adobe Community Professional Program information at https://www.adobe.com/communities/professionals/, please let us know if you are interested.</p>

<p>Someone from the selection team will contact you soon regarding the community professional program. Keep up the good work!</p>

<p>Regards,</p>

<p>The Acrobat User Community Team</p>


<p>**** Disclosure Requirements for Endorsements Received by Third Parties  ****</p>

<p>If you endorse or refer people to the Acrobat User Community in any venue,  it is our responsibility to ensure that you are aware of required compliance with the <a href="http://ftc.gov/os/2009/10/091005revisedendorsementguides.pdf">FTC’s Guidelines</a>. Both you and Adobe can be held liable under federal law for making unsubstantiated claims and for not disclosing your relationship with Adobe. In particular:</p>

<ol>
<li>Always disclose if you have received any type of incentive – free products, promotional items, travel, gifts, payment, and so on from Adobe. The disclosure must be on the same page as the endorsement.</li>
<li>Be truthful. Endorsements should not be misleading. Never make unsubstantiated or exaggerated claims about the benefits of Adobe products or programs. Any statements or endorsements about an Adobe product must be based on upon your actual experience.</li>
</ol>

Thank you again for your support of Adobe and the Acrobat User Community</p>

The issue is not the path, but the fact that when you use it the method has to run from a privileged context.
Read the reference for that parameter once more.

Edit: I see now that there's actually also a problem with your path. Try printing dataFilePath to the console just before calling RFIS and you'll see the problem.

-------------------------------------
Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67) answered 701 days ago  |   Comments (0)  |  New Comment

avatar

  |   Report
Was this answer helpful?  
0
0

avatar
Welcome to the Acrobat Answers site. You're on your way! It won't take you many more points to reach the next level: Participant. And as you accumulate more points, you're also building your reputation with the community and with AcrobatUsers.com.

I think the path is okay, I displayed it in an alert and it looked correct. (There may be a typo in my example since I couldn't paste it in.) I missed the detail of "privileged context", I'm new to javascript and scripting pdfs.

I added my form "working" folder to the security section as a privileged location and the readFileIntoStream command worked. Means we would need to get each user to do this.

The idea of attaching the xml to the pdf sounds good, but I don't think I could do that from an outside application. Each time one of these forms will be used it is copied from a template and then the xml is generated to pre fill the form. This is not done in Acrobat but in our own application and done on each individuals computer, not centrally.

Thanks for the suggestions.


Peter Mitchell answered 701 days ago  |   Comments (0)  |  New Comment

avatar

  |   Report
Was this answer helpful?  
0
0


Download
Acrobat XI trial

Get the trial now


Other Questions Needing Answers


registration problem

Asked by kari converse · no replies



link two form fields

Asked by Nancy Patt · 1 answer