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
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.
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.
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");
?
Copy link to clipboard
Copied
I believe that change should be sufficient, as it also returns a stream object.
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.
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.
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.
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...)
Copy link to clipboard
Copied
That shouldn't be the case, but if it works better with it, then leave it. It doesn't matter much.