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

HelIo, I have an Attachment button but I would like the attachment name to show in a text box. The attachment is mandatory but I'm not sure how to do this. Can you help me please? Thank you. JB.

New Here ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

HelIo, I have an Attachment button but I would like the attachment name to show in a text box. The attachment is mandatory but I'm not sure how to do this. Can you help me please? Thank you. JB.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

420

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 ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

There are a couple of ways to do this. For example, put this code in a folder level script.

this.getField("AttachName").value = dataObjects[0].name;

This code puts the "name" of the first attachment into a field named "AttachName".

You'll need to change the field name to match the one on your PDF.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

Hello Thom,

     Tank you for your response. Forgive my ignorance but, I Don't know what you mean by "Folder level " script. Could you enlighten me?

John

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 ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

My bad, I meant Document Level Script. These scripts are run when the PDF is opened, so that the attachment name is always refreshed. Here's an article on it.

Basic Document Level (Document Open) Scripts

If a script is used to add the attachment, then another way to do this is to place the name into the field in the same script that adds it.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

Thom, Thanks for the precision. I have a button for adding an attachment (Code below) I tried adding the line after both the import commands without any success. And I couldn't find where to access the document level script. Also I have a send button.

The AttachName field is mandatory so it won't send without an attachment name in the text box ("AttachName")

I apologise for my lack of knowledge however I do appreciate your help and patience.

John

** attachment button code.***

if (app.viewerVersion < 11) {

    import_pre_11();

} else {

    import_11();

}

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
LEGEND ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

You cannot skip steps... You must add the document level script, because it is what makes import_pre_11 and import_11 work. What version of Acrobat Pro do you have (if you have Acrobat Standard, get Acrobat Pro).

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 ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

LATEST

Hello sir,
Thank you for your assistance.

I have found a solution as you can see below.

JOhn

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 ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

So what are these "import_pre" functions? Where do they exists?

What errors were reported in the Console Window?  This is really important stuff. No one can help if we don't have specific information about what is happening on your form.

The code I provided depends on two things. First that there is a field named "AttachName", and second that there is an attachment in the PDF.  Another lesser assumption is that the attachment file name is in the "name" property, but this is only true if the file is imported through the Acrobat UI. It could be something different if it is imported with code.

Change the code to this:

this.getField("AttachName").value = this.dataObjects[0].path;

It explicitly calls out the document object, the previous code just assumed it, and it uses the "path" property instead of the name.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

Hello Thom,

I am not familiar enough with the Tools to know how to get error messages etc. so...
Finally I found this code which works well on the Mouseup event on a button…

this.importDataObject("MyFile");

var MyData = this.getDataObject("MyFile");

this.getField("AttachName").value = MyData.path;

This opens the import (getfile) dialog and then affects the name (as no path as such) into the textbox "AttachName"

Thank you very much for your patience and help.

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