Skip to main content
March 29, 2019
Question

JavaScript Code for Attachment, Text Field & Clear files Button

  • March 29, 2019
  • 1 reply
  • 460 views

Good day, Is it possible to get the Java script code to add attachment(file), Text field to show the file name that was attached  and the Clear files button to clear the text field and remove attachment. This is what i am looking for on the form i am trying to create. Any help would be greatly appreciated. Thanks

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
April 2, 2019

Yes and no. The code for adding an attachment is this:

this.importDataObject("TheObject");

This prompts the user with a file open dialog.  The name "TheObject" is the name of this attachment.

use this code to remove

this.removeDataObject("TheObject);

I've already answered a question about showing the attachment name here:

HelIo, I have an Attachment button but I would like the attachment name to show in a text box. The attachment is mandato…

Be aware that importing a data object can be a privileged operation, and that this code will only work in Reader if the PDF has special privileges.

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