attachment name
How to rename attached files with Adobe JS? Or at least where the name of the attachment is kept? annots.name returns different value.
How to rename attached files with Adobe JS? Or at least where the name of the attachment is kept? annots.name returns different value.
I used a button, that calls the following JS code to add an attachment.
function import_11(numb) {
console.println(numb);
try {
var annot = addAnnot({
page: event.target.page,
type: 'FileAttachment',
author: 'Form user',
name: 'File Attachment',
point: [oFAP.x, oFAP.y],
contents: 'File attachment for the question ' + numb + ' made on: ' + util.printd('yyyy/mm/dd HH:MM:ss', new Date()),
attachIcon: 'Paperclip'
});
annot.cAttachmentPath; // Prompt user to select a file to attach
oFAP.x += 18; // Increment the x location for the icon
} catch (e) {
app.alert({
cMsg: 'Could not attach file. Please report this error.',
cTitle: 'File attachment error',
nIcon: 3,
nType: 0
});
}
}
So the reason for the error is that you have annotations that are not file attachments. In order for the script to work it needs to sort for the file attachment type.
This script will work for displaying all the attached file names
var annots = this.getAnnots({
nPage:0,
nSortBy: ANSB_Author,
bReverse: true
});
console.show();
var aAttach = annots.filter(function(a){return (a.type=="FileAttachment");});
console.println("Number of Annotations: " + aAttach.length);
for (var i = 0; i < aAttach.length; i++)
console.println("> " + aAttach.attachment.name);
On another note, this line in you code for adding the attachment does nothing.
annot.cAttachmentPath; // Prompt user to select a file to attach
The "cAttachmentPath" property is only used when setting a known attachment path in the "addAnnot()" function.
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.