How to Add Asterisks Around a Value in an Adobe Acrobat Code 39 Barcode
Question details
The user needs to format a text value entered in a PDF form by automatically appending an asterisk to both the beginning and the end, and then display this combined string in a read-only Code 39 barcode field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or modifying an interactive PDF document where a Code 39 barcode must dynamically pull data from a source field and format it with mandatory start/stop characters.
- Observed behavior
- The Code 39 barcode needs a reliable script to fetch the source field's input, combine it with the required asterisks, and output the readable barcode.
Ensure you have access to the 'Prepare Form' tool in Adobe Acrobat and make a note of the exact field name of your source text box before applying the custom script.
Apply a Custom JavaScript Calculation to the Barcode Field
Use Adobe Acrobat's built-in calculation properties to automatically pull the text field value, append the asterisks, and generate the correct Code 39 barcode.
Code 39 barcodes require asterisks (*) at the beginning and end of the data string to act as start and stop characters for the scanner. You can automate this insertion using a simple JavaScript calculation applied directly to the barcode field.
Open your PDF document in Adobe Acrobat, navigate to the Tools menu, and select 'Prepare Form' to enable form field editing.
Right-click on the read-only Code 39 barcode field you wish to update and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab inside the Properties dialog. Select the 'Custom calculation script' radio button and click 'Edit'. In the JavaScript Editor, paste the following code: event.value = "*" + this.getField("A").valueAsString + "*";
In the pasted script, replace the letter "A" with the exact name of the text field where users will enter their data. Click 'OK' to save the script.
Close the Properties dialog and exit Prepare Form mode. Type a sample value into your source text field and click outside the box to verify that the barcode updates with the appended asterisks.

Manage and Fill Interactive PDF Forms with WPS Office
If you need a fast and reliable tool to fill, edit, and manage interactive PDF documents, WPS Office offers a comprehensive PDF editor. It streamlines form handling and provides seamless document management in a single, unified application.
- 1. Download the Software: Visit the official WPS Office website to download and install the free software on your device.
- 2. Open Your PDF Form: Launch WPS Office and open your interactive PDF document using the built-in PDF reader.
- 3. Fill and Save: Click on the form fields to input your data easily, then save the completed document for sharing or printing.

Frequently Asked Questions
Why does a Code 39 barcode require asterisks?
The Code 39 standard utilizes asterisks as distinct start and stop characters. They signal to the hardware barcode scanner exactly where the encoded data sequence begins and ends, preventing reading errors.
Why isn't my PDF barcode updating automatically when I enter text?
Calculation scripts typically run when a field loses focus. Ensure you click outside the text box or press 'Enter' after typing. You can also open the source field's Properties, go to the 'Options' tab, and check 'Commit selected value immediately' for real-time updates.
How do I find the exact name of my source text field in Acrobat?
In Adobe Acrobat's 'Prepare Form' mode, double-click the target text field to open its Properties dialog. The exact field name is displayed at the top of the 'General' tab.
Can I use this same script for other barcode formats like QR codes?
No. This specific string manipulation that appends asterisks is unique to the Code 39 format requirements. Other formats, such as Code 128 or QR codes, have different start/stop mechanisms and do not require manual asterisk insertion.




