Copy link to clipboard
Copied
I need to create a button or link that allows a Reader user to click and attach a resume file. Most attachments will probably be Word documents.
Using Acrobat Pro XI, is it possible to add that type of button to a form?
Here's a link to a sample document: Dropbox - importTest_20150411_1.pdf
It contains a single button that uses some JavaScript, most of which is contained in a document-level JavaScript. You'll have to study it a bit to figure out how it works. It relies on using the cAttachmentPath annotation property, which really acts like a method to prompt the user to attach a file. If Acrobat is used and it's prior to 11, the normal type of file attachment is used, but this won't work with Reader unless the
...Copy link to clipboard
Copied
If all you did was copy the code from the button, then it won't work. You also need to include the code that's in the document-level JavaScript, which is what the code in the button's Mouse Up event calls.
Copy link to clipboard
Copied
Hi
This script is working fine for me, I can see the attachments in the attachment panel.
I was wondering someone could tell me how to indicate to the person viewing the PDF that there is an attachment(s) on the PDF. Maybe a hidden text field that becomes visible when attachments are present? Is this possible? Or is the fix to change the document level script to put the attachment icons on the page vs "below and to the left of the bottom left corner of the page"
Thanks in advance for any ideas on this.
Copy link to clipboard
Copied
The script controls where the attachment annotation is placed on the page. It defaults to a location off of the page, but you can change this to whatever you want. If you know the coordinates where you want it to appear, I can suggest a revision to the code that you can use.
Copy link to clipboard
Copied
Thanks George. I am not sure how to give you coordinates. The PDF page size is 8.5" x 15".
I placed a text box on the PDF and positioned it. The left measurement was 39p0, bottom was 1p0.
Also, this form has three pages. Is the attachment placed on whatever page you place the button? And, there is always the possibility that a user may have more than one attachment.
For my purposes, a hidden text box that becomes visible when an attachment comment is placed on the page would work just as well, too. Just want to make it simple for the users.
Thanks again
Copy link to clipboard
Copied
Hi All,
I'm trying to add attachment in PDF from using Adobe Livecycle ES 8.2 designer tool.Used the custom script in button click, but it's not working. Please someone quickly advise me and share the custom script to add attachment in button click event.
Script is
var annot = this.addAnnot({
page: 0,
type: "FileAttachment",
point: [500, 500],
noView: true,
author: "Attachment"
});
annot.cAttachmentPath;
var attachmentObj = annot.attachment;
if (attachmentObj !== null) {
app.alert("Add this file: " + attachmentObj.name);
var l = this.getField("lst1");
l.insertItemAt(attachmentObj.name, 0);
}
Copy link to clipboard
Copied
Where in Javascript do you post this code? In Document Javascript I already have Javascript for another action item. Can I just add this code to the existing one? I am using Acrobat Pro DC.
Copy link to clipboard
Copied
You can add the code to an existing document-level JavaScript, or just add another and place it there.
Copy link to clipboard
Copied
Thanks. What's the code that gets pasted into Document Script? So after I copy and paste the button and then add the document script it should work?
Copy link to clipboard
Copied
George,
The code you posted has been of great help, thank you, particularly as I'm new to JS and I thought I'd done good but of course then realised that no user with just Reader can add attachments "as attachments".
I have a information message added into a textbox for the user so they can see that the file has been added. I can't seem to get this code to work with your helpful example, even though I have replaced with your variable "annot". Could you spare a moment to help please or tell me where to place it in your code?
This is my message code:
this.importDataObject("MyFile");
var annot = this.getDataObject("MyFile");
this.getField("fileName").value = annot.path + " has been added to the document."; // change the field name as needed
Best regards
Rob
Copy link to clipboard
Copied
Hi,
I'm trying to add attachment in PDF from using Adobe Livecycle ES 8.2 designer tool.Used the custom script in button click, but it's not working. Please someone quickly advise me and share the custom script to add attachment in button click event.
Script is
var annot = this.addAnnot({
page: 0,
type: "FileAttachment",
point: [500, 500],
noView: true,
author: "Attachment"
});
annot.cAttachmentPath;
var attachmentObj = annot.attachment;
if (attachmentObj !== null) {
app.alert("Add this file: " + attachmentObj.name);
var l = this.getField("lst1");
l.insertItemAt(attachmentObj.name, 0);
}
Copy link to clipboard
Copied
This code will not work in an LCD form. You should post your question in the relevant forum: LiveCycle Designer
Copy link to clipboard
Copied
I've added the button and it works flawlessly. I see that if I open the document in Reader the files don't show anywhere. They are there, checked with XI just to make sure. Is there a way to show the attachments within the PDF itself instead of just in the attachment pane that don't exist in DC?
Copy link to clipboard
Copied
The files attached using the code above will not appear in the Attachments panel.
They are a part of an annotation (a comment), and will therefore appear in the Comments panel.
Copy link to clipboard
Copied
Since that code only works for images, I'll wait until you get a chance to post JavaScript for Reader XI and Reader DC users to attach a file.
Copy link to clipboard
Copied
Hello.
I was able to get this code to work, to add one file. Is there a way to attach multiple files?
try {
var annot = this.addAnnot({
page: 0,
type: "FileAttachment",
point: [500, 500],
noView: true,
author: "Attachment"
});
annot.cAttachmentPath;
var attachmentObj = annot.attachment;
if (attachmentObj !== null) {
app.alert("Add this file: " + attachmentObj.name);
var l = this.getField("lst1");
l.insertItemAt(attachmentObj.name, 0);
}
}
catch(e) {
if (e.name == "NotAllowedError") {
// do nothing
}
}
Copy link to clipboard
Copied
Run the same code multiple times. You can do it in a for-loop.
Copy link to clipboard
Copied
This "Attach File" button script works great... but I want to use it together with the PDF form 'image field' that uses the script:
event.target.buttonImportIcon();
How can I combine it with your script so it will show the image and attach it in the same time:
if (app.viewerVersion < 11) {
import_pre_11();
} else {
import_11();
}
Thanks, JanB