Adding a File to a PDF using Javascript
Copy link to clipboard
Copied
Good day everyone
I was wondering if there's a way to know via javascript, if at least one file is attached to said PDF?
Im prsently using this code to let someone attch a file:
var myDoc = event.target;
var sFile = "myFile"
myDoc.importDataObject(sFile);
app.execMenuItem("ShowHideFileAttachment");
But after that, how can i keep track of this? I could use right now a variable to tell me its been added... but what if a user deletes the attachement?? can i track that? if so, i could update said variable maybe??
Any ideas??? thx so much for the help again 🙂
Patrick
Copy link to clipboard
Copied
Yes, here's a link to the JS reference entry
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#dataobjects
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Sounds good, i will take a look at the reference link just to help me understand better what is going on.
Thx for the input. Would you be able to capture via javascript, if the person did press the remove attachment button???
Copy link to clipboard
Copied
No, There are no JavaScript events associated with actions taken at the application level.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi,
Unless I'm mistaken, this only works if the attachment has been imported manually... not with the importDataObject method!
@+
Copy link to clipboard
Copied
Hi,
Unless I'm mistaken, this only works if the attachment has been imported manually... not with the importDataObject method!
@+
By bebarth
the importDataObject method does add to the standard data objects. It's the FileAttachment annot that doesn't add to the dataObjects (as try67 pointed out).
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
You can check the length of the dataObjects array, but this only works for actual Attachments. If they used the Attach File commenting tool, that won't appear there. To detect that you would need to scan the entire annotations array of the file, checking if any of them are of the "FileAttachment" type.

