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

Javascript To Insert Attachment On A PDF

New Here ,
May 28, 2019 May 28, 2019

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.1K

Translate

Translate

Report

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

Votes

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Hi try67,

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

Votes

Translate

Translate

Report

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