Expand my Community achievements bar.

execMenuItem for Attach a File?

Avatar

Former Community Member
Acrobat will allow you to attach a file with a command from the 'Document' menu list, named 'Attach a File...'.



I've used app.execMenuItem("SaveAs"); triggered by a Button click before.



Wondering if there is a similar script for the Menu Item 'Attach a File'.

I can't find it documented anywhere.



I've tried app.execMenuItem("AttachaFile"); and a few other variations without any success.



Anyone know how to do this?
4 Replies

Avatar

Former Community Member
Jerome,

First of all, do you care if the attachment is a page level or document level attachment. Dynamic pdfs only allow document level attachments.

If you're expecting a page level attachment and you don't need any of the dynamic form features then you need to make sure your doc is saved as a static pdf. In which case the menu call should work.

To add a document level attachment to a dynamic pdf, you can't use the menu call -instead try something like this attached to the click event of a button:



var i = parseInt(attachCount.rawValue);

var oDoc = event.target;

oDoc.importDataObject("newattach" + i);

i++;

attachCount.rawValue = i;

}

else

{xfa.host.messageBox("Invalid attachment type!");

oDoc.removeDataObject("newattach" + i);

}



'commonScript' is a scriptObject (variable) listing the types of attachments you're willing to take. For example...



function hasValidExt(inPath)

{

var returnValue = false;

var uPath = String(inPath.toUpperCase());



if (uPath.indexOf(".DOC") > 0)

returnValue = true;

return returnValue;

}



The sample javascript is taken from a form that contains some other functionality associated with the attachments -so I needed a way to number/count the attachments in the subform. There is a hidden text field 'attachCount' that hold the doc count (var i). Of course there are other ways to do this.

If you're expecting to attach more than one file to the doc, then you'll still need to add the var i count in order to not rewrite the file every time you hit the attach button.



Hope this helps.

Avatar

Former Community Member
hi jennifer,



i have tried out your script to attach files, but it doesn´t work.

i use a dynamic form. do you have a "complete" script ?



thanks in advance

herbert

Avatar

Level 6
Herbert,



I don't think there's more code to provide. I've tried this approach in a dynamic form and it works for me. However, this won't work in the free Adobe Reader unless you've extended the PDF's usage rights using LiveCycle Reader Extensions Server. The ability to attach files is one of the "dormant" features of the free Reader. When you try to run a script and it doesn't work, CTRL-J brings up the Acrobat console. There you usually find a useful error message.



I hope this helps.



Jared Langdon

J. Langdon Consulting, Inc.

Avatar

Former Community Member
jaredn,



thanks for your reply. i just put this js-code to the click event of a button:



var i = parseInt(attachCount.rawValue);

var oDoc = event.target;

oDoc.importDataObject("newattach" + i);

i++;

attachCount.rawValue = i;



and it works perfect.



another question:

is it possible to show the attachment-view with javascript after adding an attachment?



regards

herbert