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

Acrobat Form - Getting an "Attach a File" button to work properly in Forms

Explorer ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

I am using Acrobat Pro DC 2019.

 

I have created a button, with the intention of allowing the user to attach a document to the PDF. 

Screen Shot 2019-10-31 at 3.36.54 PM.png

Screen Shot 2019-10-31 at 3.39.36 PM.png

 

My settings for the Button are shown below:

Screen Shot 2019-10-31 at 3.37.30 PM.pngScreen Shot 2019-10-31 at 3.37.17 PM.pngScreen Shot 2019-10-31 at 3.37.03 PM.png

 

However, all this does is open the Attachment pane in Acrobat, where I can Add an Attachment as a separate step from a fly-out menu. Would this even work for the casual Adobe Reader user? How do I get the button to open a file browser window to attach a file directly?

TOPICS
PDF forms

Views

1.4K

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 ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

You have a bit of a problem with this one. Adding attachments is a protected operation. Doing it the traditional way won't work from a script in a PDF. However, you can add a "File Attachment Annotation" from a form script. 

Add this script to your button:

 

this.addAnnot({type:"FileAttachment", rect:[200,200,200,200], page:0});

 

This places a paperclip file attachment annot on the bottom left of the first page. Change the rect and page parameters to change the location.

 

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
Explorer ,
Nov 01, 2019 Nov 01, 2019

Copy link to clipboard

Copied

Can you clarify more about how to get the paperclip icon to appear next to the File Attachment button?

This is where it appears.

 

Screen Shot 2019-11-01 at 12.40.54 PM.png

How do I pre-define where the paperclip should appear before the File Attachment button is pushed?

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 ,
Nov 01, 2019 Nov 01, 2019

Copy link to clipboard

Copied

The location of the paperclip is determined by the "rect" property passed into addAnnot function. In this case I've simply defined a centerpoint, a full rectangle is unnecessary because the attachment icon is a fixed size. If you want it next to the button then you have to calculate where this center point should be relative to the button location. 

Here's an article on coordinates and placing annotations in a PDF:

https://www.pdfscripting.com/members/PDF-Page-Coordinates.cfm

 

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
Community Expert ,
Nov 01, 2019 Nov 01, 2019

Copy link to clipboard

Copied

The coordinates of the button, from a script inside the button (i.e. the mouse up action), are this

 

var fieldRect = event.target.rect;

 

This is your starting point for calculating the location of the attachement annotation.

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
Explorer ,
Nov 04, 2019 Nov 04, 2019

Copy link to clipboard

Copied

I am attempting to shift the location of the paperclip that appears once an attachment is attached.

 

So, my Actions > Mouse Up > Run a Javascript code for the buttons is:

 

this.addAnnot({type:"FileAttachment", rect:[200,200,200,200], page:0});

 

I am unsure where the second line of code ("var fieldRect = event.target.rect;") that you provided should go. Above this first line in the same Mouse Up code? I have tried some combinations, but without results.

 

My understanding (which is limited, to be sure) is that changing the coordinates in the "rect:[200,200,200,200]" section of code should move the location of the paperclip, but it does not. I have tried various combinations like [0,0,600,150] but the paperclip appears always in the same place. 

 

From your response, my understanding is that the paperclip coordinates should be defined relative to the button, but since my attempts to move the paperclip at all by changing the coordinates failed, I am confused about how to this.

 

Your help is greatly appreciated as I work through this client request that I am unfamiliar with. Thank 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 ,
Nov 04, 2019 Nov 04, 2019

Copy link to clipboard

Copied

So, the idea is to figure out the rectangle location up front, then apply the attachment annotation. Did you read the article at the link I provided in my first post? It covers the details of annotation placement.  

 

If you just used the button location, so the paperclip apears on top of the button. The code would look like this.

this.addAnnot({type:"FileAttachment", point:event.target.rect, page:event.target.page});

 

Notice that there are a few changes here. "event.target" references the target of the script, which is the button.  So the script uses both the button rectangle and the button page, ensuring that the attachement annot is on the same page and location as the button. Also note that the "point" parameter is used instead of rect. This is more correct for placing an attachment annot, because the attach icon does not change size. You may not see the paperclip icon because it might be hidden behind the button, but the attachment file will appear in the attachments tab.

 

 

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
Explorer ,
Nov 04, 2019 Nov 04, 2019

Copy link to clipboard

Copied

THANK YOU!

The paperclip does appear mostly underneath the button (and peak out at the bottom), but otherwise this is perfect.

I attempted to read the article you sent, but it was behind a paywall and I was not able to access it.

I really appreciate your help on this!

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

Copy link to clipboard

Copied

LATEST

Actually, that article is not behind a paywall. My mistake for posting an incorrect URL. Please read it. 

https://www.pdfscripting.com/public/PDF-Page-Coordinates.cfm

 

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
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

Adding/removing attachments in Acrobat Reader requires the form to be Reader-enabled with the right "EFModif". This can only be applied through the server product Acrobat Reader Extensions in AEM Forms (formerly LiveCycle Reader extensions). 

https://help.adobe.com/en_US/AEMForms/6.1/AdminHelp/WS92d06802c76abadb-5145d5d12905ce07e7-7ffa.2.htm...

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 ,
Nov 01, 2019 Nov 01, 2019

Copy link to clipboard

Copied

Fortunately, the attachement annotation can be used in Acrobat Reader without any Reader Extensions.

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