Skip to main content
Participating Frequently
May 28, 2019
Answered

Javascript To Insert Attachment On A PDF

  • May 28, 2019
  • 2 replies
  • 2123 views

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

This topic has been closed for replies.
Correct answer try67

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)});

2 replies

Participating Frequently
May 29, 2019

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.

try67
try67Correct answer
Brainiac
May 29, 2019

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)});

Participating Frequently
May 29, 2019

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.

try67
Brainiac
May 28, 2019

Yes, you can do it using the importDataObject method of the Document object.

Participating Frequently
May 28, 2019

Hi, Thanks for quick response. Can you please be more specific?

Participating Frequently
May 28, 2019

Is it also possible that the script will choose the files to be attached by using some code like filename*.doc?