Copy link to clipboard
Copied
Hi All,
I have got a form with a button which adds attachments which works great, however i have also got a button to reset the form which clears all the fields however it does not delete the attachments.
Is there a script i can use in the reset button which can delete attachments same time it clears the form?
Thanks in advance
You can use this code to do it:
if (this.dataObjects!=null) {
for (var i=this.dataObjects.length-1; i>=0; i--) {
this.removeDataObject(this.dataObjects[i].name);
}
}
Follow up: It seems you want to use this in Reader. In that case the attachments are actually comments, and can be removed using this code:
this.syncAnnotScan();
var annots = this.getAnnots();
if (annots!=null) {
for (var i=annots.length-1; i>=0; i--) {
var annot = annots[i];
if (annot.type=="FileAttachment") annot.destroy();
}
}
Copy link to clipboard
Copied
In Acrobat scripting, attachments are called "DataObjects". Use the "doc.removeDataObject()" function.
Here's the reference entry
Copy link to clipboard
Copied
Thanks for your reply. However i want to delete all attachments without specifically naming them in the script as i want it so that when someone fills out the form and presses "Clear" button the form resets and all attachments (could be named anything) are deleted. Would love to know whether this is possible and if there is any other way to get round this?
Much appreciated
Copy link to clipboard
Copied
You can use this code to do it:
if (this.dataObjects!=null) {
for (var i=this.dataObjects.length-1; i>=0; i--) {
this.removeDataObject(this.dataObjects[i].name);
}
}
Copy link to clipboard
Copied
Follow up: It seems you want to use this in Reader. In that case the attachments are actually comments, and can be removed using this code:
this.syncAnnotScan();
var annots = this.getAnnots();
if (annots!=null) {
for (var i=annots.length-1; i>=0; i--) {
var annot = annots[i];
if (annot.type=="FileAttachment") annot.destroy();
}
}
Copy link to clipboard
Copied
This works perfectly! Thanks a lot!!
Copy link to clipboard
Copied
- - - - - - -- - - - -
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more