Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript To Insert Attachment On A PDF

New Here ,
May 28, 2019 May 28, 2019

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

TOPICS
Acrobat SDK and JavaScript , Windows
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 29, 2019 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)});

Translate
Community Expert ,
May 28, 2019 May 28, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2019 May 28, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2019 May 28, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2019 May 28, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2019 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2019 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)});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2019 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2019 May 29, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2019 May 30, 2019
LATEST

Hi try67,

It works, you are a genius. Thank you very much for sharing your knowledge. More power to you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines