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

filepath for a .txt file attached to a pdf form

Explorer ,
Apr 20, 2019 Apr 20, 2019

Copy link to clipboard

Copied

Hello, all,

I have a pdf form which contains fields for all my clients' contact details (Name, Address, Telephone, Email, Website, Instagram etc). Thanks to a LOT of help from this forum, I have set it up so that all of these fields are populated when I select the company name from a dropdown list. The data is stored in a tab-delimited file at a fixed, specified location on my hard drive. (oh, I'm on Acrobat DC).

What I'd REALLY like to be able to do, is attach the .txt file to the pdf itself, so that it doesn't matter where I move it to, it will carry its own datasheet around with it.

The script I use currently to get the data from the txt file is:

var Trusted_readContactDetails = app.trustedFunction(readContactDetails);

function readContactDetails()

{

app.beginPriv();

   var oFile = util.readFileIntoStream("/Macintosh HD/Users/somefoldernames/morefolders/InvoiceContacts.txt");   

   var cFile = util.stringFromStream(oFile, "utf-8");    

   var yourCode = cFile.split("\n");           

   var i;     

   var aListEntries = [], cVal;

for (i = 0; i < yourCode.length; i++){

    var tempArray = yourCode.split('\t');

    cVal = tempArray.shift();

    aListEntries.push([cVal,tempArray.join(";")]);

}

  this.getField("SelectCompany").setItems(aListEntries);

app.endPriv();

}

What I'd like to know is what path do I need to specify to reference the .txt file if it is attched to the parent pdf?

Any help gratefully recieved, and thanks in advance for your time.

Nathan

TOPICS
Acrobat SDK and JavaScript

Views

1.1K

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

correct answers 1 Correct answer

Community Expert , Apr 21, 2019 Apr 21, 2019

Try adding "this." before it. Also, I think you can get rid of all the trusted function stuff. It's not necessary when reading the data from an attached file.

Votes

Translate

Translate
Community Expert ,
Apr 20, 2019 Apr 20, 2019

Copy link to clipboard

Copied

No path at all. You would need to use a different approach. Namely, read the contents of the file using the getDataObjectContents method, instead of the readFileIntoStream method.

Votes

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
Explorer ,
Apr 20, 2019 Apr 20, 2019

Copy link to clipboard

Copied

Ah, now this sends me down a path to uncharted territory for my limited knowledge.

Does the getDataObjectContents require any additional coding, or can I simply replace:

var oFile = util.readFileIntoStream("/Macintosh HD/Users/somefoldernames/morefolders/InvoiceContacts.txt");

With:

var oFile = getDataObjectContents("InvoiceContacts.txt");

?

Votes

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
Community Expert ,
Apr 21, 2019 Apr 21, 2019

Copy link to clipboard

Copied

I believe that change should be sufficient, as it also returns a stream object.

Votes

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
Explorer ,
Apr 21, 2019 Apr 21, 2019

Copy link to clipboard

Copied

Hmm...

If only I could tell you that that had worked.

All that happens now is that the console throws back that "getDataObjectContents is not a function".

Any ideas where the problem could lie? I'm afraid I'm now well beyond my capacity for tinkering.

Thanks again.

Votes

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
Community Expert ,
Apr 21, 2019 Apr 21, 2019

Copy link to clipboard

Copied

Try adding "this." before it. Also, I think you can get rid of all the trusted function stuff. It's not necessary when reading the data from an attached file.

Votes

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
Explorer ,
Apr 21, 2019 Apr 21, 2019

Copy link to clipboard

Copied

You're amazing!

It needed to be "this.getDataObjectContents", and now it's working perfectly.

I'm really grateful to you for the speedy replies, and your willingness to help out an enthusiastic beginner. Thanks so much.

Votes

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
Explorer ,
Apr 22, 2019 Apr 22, 2019

Copy link to clipboard

Copied

(I don't know if I just didn't do it very well, but when I tried to remove the trusted function aspect of the function, it threw back security errors at me, which stopped immediately when I put it back as it was. It seems that the getDataObjectContents might just have privilege issues after all...)

Votes

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
Community Expert ,
Apr 23, 2019 Apr 23, 2019

Copy link to clipboard

Copied

LATEST

That shouldn't be the case, but if it works better with it, then leave it. It doesn't matter much.

Votes

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