How to Add File Attachments and Display File Names in LiveCycle Designer
Question details
The user wants to configure a PDF form to accept file attachments and dynamically display the attached file's exact name next to the attachment button.

- Product
- Adobe LiveCycle Designer
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where users need to upload supporting documents and immediately see the name of the file they attached for verification.
- Observed behavior
- Requires a custom scripting solution to bind the attachment upload action to a specific text field that updates with the file name.
Ensure your LiveCycle Designer form is configured to save as a Dynamic XML Form rather than a Static PDF, as static forms often restrict real-time updates to text fields via scripts.
Use JavaScript to Bind the Attachment Action to a Text Field
Implement a custom JavaScript snippet on the button's click event to invoke the PDF attachment dialog and extract the file name to a target text field.
Because LiveCycle Designer uses the XFA framework, handling attachments requires bridging the form design with Acrobat's JavaScript Object Model. The script will prompt the user to select a file, attach it to the PDF data object, and then retrieve the file name property to populate your display field.
Add a 'Button' object to act as the attachment trigger. Next to it, insert a 'Text Field' object and name it 'FileNameDisplay' in the Hierarchy palette. Set the Text Field's access to 'Read Only' so users cannot manually type over the file name.
Select the Button object, go to the Window menu, and click on 'Script Editor'. Set the language dropdown to 'JavaScript', the 'Show' dropdown to the 'click' event, and ensure the 'Run At' setting is set to 'Client'.
Input a script utilizing the 'event.target.importDataObject' method. For example: 'var myDoc = event.target; myDoc.importDataObject("UserAttachment");'.
Add logic directly below to retrieve the name of the newly attached data object and assign it to the text field's raw value: 'var myData = myDoc.getDataObject("UserAttachment"); if (myData) { FileNameDisplay.rawValue = myData.name; }'.

Easily Add Attachments to PDFs with WPS Office
If writing complex JavaScript in LiveCycle Designer is too time-consuming or overkill for your needs, you can use WPS Office to directly attach files to any standard PDF document. WPS PDF provides a highly intuitive interface to embed files, add comments, and modify PDFs without any coding.
- 1. Open your PDF Document: Launch WPS Office and open the PDF file where you need to append supplementary files.
- 2. Access the Comment Tools: Navigate to the 'Comment' tab on the top ribbon to access the advanced annotation tools.
- 3. Insert the Attachment: Click the 'Attachment' button, then click on the specific area of the PDF page where you want the attachment icon to be placed.
- 4. Select the File: Choose the file you wish to attach from your computer's local storage and customize the icon's color and appearance.

Frequently Asked Questions
Why isn't the file name updating when I click the attachment button in LiveCycle?
This usually happens if the script is referencing the wrong text field name, or if the PDF is saved as a Static PDF instead of a Dynamic XML PDF. Double-check your object naming in the Hierarchy palette and ensure the script correctly points to the 'rawValue' of the text field.
Can I use FormCalc instead of JavaScript for attachments?
FormCalc has limited support for the advanced Acrobat Object Model required to handle native file attachments and data objects. JavaScript is the universally recommended language for executing attachment scripts in LiveCycle Designer.
Will forms created with dynamic LiveCycle scripts work in all PDF viewers?
No. Forms utilizing complex XFA (XML Forms Architecture) scripts, such as dynamic attachment handling, typically require Adobe Acrobat or Adobe Reader. Many third-party browsers and basic PDF viewers do not fully support XFA JavaScript.
How do I remove an attachment using a button script?
You can create a 'Remove Attachment' button and bind a JavaScript event using the 'event.target.removeDataObject("AttachmentName")' method to delete the specific attachment from the PDF, followed by clearing the text field's rawValue.




