Copy link to clipboard
Copied
Is there a java script I can use to insert an attachment into pdf. I am working with thousand of files and I have to manually insert all the attachment on each of them. Thanks in advance
1 Correct answer
OK, that's not quite what you described before. If the name of the file to attach can be derived from the name of the PDF file then it's not too difficult. You can use this code as a part of an Action to do it:
var attachmentFileName = this.documentFileName.replace(".pdf", "_Attachment 1.xlsx");
this.importDataObject({cName: attachmentFileName, cDIPath: this.path.replace(this.documentFileName, attachmentFileName)});
Copy link to clipboard
Copied
Yes, you can do it using the importDataObject method of the Document object.
Copy link to clipboard
Copied
Hi, Thanks for quick response. Can you please be more specific?
Copy link to clipboard
Copied
Is it also possible that the script will choose the files to be attached by using some code like filename*.doc?
Copy link to clipboard
Copied
No. You have to know the exact file path, or the user has to select it.
All of the information you need is available in the Acrobat JavaScript API Reference: JavaScript for Acrobat
Copy link to clipboard
Copied
Maybe somebody here can help me. Doing the manual inserting of the attachment is eating much of my time. Please see how my files look below:
DHIE12-SHAI-SUXXX-66-502202-0001_revA.pdf
DHIE12-SHAI-SUXXX-66-502202-0001_revA_Attachment 1.xlsx
DHIE12-SHAI-SUXXX-66-700101-0001_revC.pdf
DHIE12-SHAI-SUXXX-66-700101-0001_revC_Attachment 1.xlsx
DHIE12-SHAI-SUXXX-66-700104-0001_revA.pdf
DHIE12-SHAI-SUXXX-66-700104-0001_revA_Attachment 1.xlsx
DHIE12-SHAI-SUXXX-66-700105-0001_revA.pdf
DHIE12-SHAI-SUXXX-66-700105-0001_revA_Attachment 1.xlsx
DHIE12-SHAI-SUXXX-66-700110-0001_revA.pdf
DHIE12-SHAI-SUXXX-66-700110-0001_revA_Attachment 1.xlsx
DHIE12-SHAI-SUXXX-66-700111-0001_revA.pdf
DHIE12-SHAI-SUXXX-66-700111-0001_revA_Attachment 1.xlsx
What i need to do is to insert the excel file as attachment to it's corresponding pdf.
Thank you very much in advance.
Copy link to clipboard
Copied
OK, that's not quite what you described before. If the name of the file to attach can be derived from the name of the PDF file then it's not too difficult. You can use this code as a part of an Action to do it:
var attachmentFileName = this.documentFileName.replace(".pdf", "_Attachment 1.xlsx");
this.importDataObject({cName: attachmentFileName, cDIPath: this.path.replace(this.documentFileName, attachmentFileName)});
Copy link to clipboard
Copied
I knew it. I know it is possible. Thank you very much.
Now my problem is how to apply it, I am using Acrobat X. How can I activate this script? Sorry for the trouble i caused you.
Copy link to clipboard
Copied
Do you have Acrobat X Pro? If so, you can create a new Action via Tools - Action Wizard and have it execute the code, and then run it on your files.
Copy link to clipboard
Copied
Hi try67,
It works, you are a genius. Thank you very much for sharing your knowledge. More power to you.

