Copy link to clipboard
Copied
I need to add the ability to attach a file to a PDF form. The file type that needs to be attached would most likely be a pdf, docx, or doc (if that matters). I'm working in Acrobat Pro DC, but the form will need to work in Reader as well. I think Java Script can accomplish this, but I have no idea how to write Java.
Thanks in advance for your help!
Copy link to clipboard
Copied
Here's how to create an "Attach File" button in a form in Acrobat Pro DC (as of Jan. 4, 2017):
1. In Acrobat Pro DC, go to Tools>Prepare Form
2. Add a button to your form by clicking on the "OK" icon and click the desired location on your form for the button.
3. Right click on the button and go to Properties. Set whatever you want in the General, Appearance, Position, and Options tabs.
4. In the Actions tab, under Select Action choose Run a Java Script. Click Add and copy and paste this text:
if (app.viewerVersion < 11) {
import_pre_11();
} else {
import_11();
}
5. Close out of Prepare Form mode and go to Tools>Java Script
6. Click on Document Java Scripts, and in Script Name type import_file, click Add, and then copy and paste this text:
// Initialize attachment number
attachment_num = 1;
// Initial location of file attachment icon
// The x value is incremented below
var oFAP = {x_init: -72, x: -72, y: -72}; // Below lower-left corner of the page
function import_pre_11() {
if (app.viewerType === "Reader") {
app.alert({
cMsg: "You must user Reader version 11 or later to attach files to this form.",
cTitle: "Attach File Error",
nIcon: 3,
nType: 0
});
return;
}
// Prompt user to import a file
app.alert({
cMsg: "Click the OK/Open button after selecting the file from your system that you want to attach.",
cTitle: "Attach File",
nIcon: 3,
nType: 0
});
try {
var rc = this.importDataObject("Attachment" + attachment_num);
if (rc) {
attachment_num += 1;
app.alert({
cMsg: "Attachment successful.\r\rOpen the Attachments panel to access the attached file(s).",
cTitle: "Attachment Successful",
nIcon: 3,
nType: 0
});
} else {
app.alert({
cMsg: "Attachment cancelled.",
cTitle: "Attachment Cancelled",
nIcon: 3,
nType: 0
});
}
} catch (e) {
app.alert({
cMsg: "Could not attach file.",
cTitle: "Could not attach file",
nIcon: 3,
nType: 0
});
}
}
function import_11() {
try {
var annot = addAnnot({
page: event.target.page,
type: "FileAttachment",
author: "Form user",
name: "File Attachment",
point: [oFAP.x, oFAP.y],
contents: "File attachment 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.\r\rPlease report this error.",
cTitle: "File attachment error",
nIcon: 3,
nType: 0
});
}
}
7. And you are done! To view attached documents, go to View>Navigation Pane>Attachments.
Special thanks to George_Johnson​ for his help!
Copy link to clipboard
Copied
You can manually go to the navigation pane>attachments (the menu on the left side) to see existing attachments and add or delete.
OR
I made an action so that when a user clicks the attach button the navigation pane automatically opens.
Copy link to clipboard
Copied
Thank you sooooo very much. It is 2020 and this resource still applies.
Copy link to clipboard
Copied
Hi, i need to attach a vcf to a pdf so that a user can click a button and open it. I've tried everything (including the above) and it just links back to my C: drive as the location of the file instead of a file within the document. Once i distribute it the link to my drive will be broken. I've got a big pitch to a law firm in a couple days and would really like this to make it easy for them. I can't do a link to dropbox or other sites because of the strict security. HELP!