PDF Editing Issues

How to Keep Only the Last 12 Digits of a Barcode in an Acrobat Form

Steve KSteve K Nov 5, 2026 868 views

Question details

The user needs to process scanned barcode data (such as a 34-digit tracking number) within a PDF form field to automatically retain only the final 12 digits.

How to Keep Only the Last 12 Digits of a Barcode in an Acrobat Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Scanning long barcodes into a PDF form field where only a specific trailing subset of characters is required for tracking purposes.
Observed behavior
The form field successfully captures the full barcode string but needs to be configured with JavaScript to automatically trim the input down to the last 12 characters upon entry.
Before you start

Confirm that your barcode scanner is configured to act as a keyboard wedge, meaning it inputs data directly into the active field and triggers standard field events (like 'Enter') upon completion.

Solution 1Recommended

Apply a Custom Calculation Script to the Destination Field

Add a JavaScript snippet to the text field's calculation properties to automatically trim the value to the last 12 digits.

This method relies on the scanning process triggering the same field events as manually entering and submitting a value.

Using the substr(-12) function in JavaScript ensures that no matter the length of the original scanned barcode, only the final 12 characters are extracted and kept in the field.

1
Open Field Properties

Open your PDF form in edit mode. Right-click the destination text field where the barcode will be scanned and select 'Properties'.

2
Navigate to the Calculate Tab

In the Text Field Properties dialog box, click on the 'Calculate' tab to set up automatic field calculations.

3
Enter the JavaScript

Select 'Custom calculation script' and click the 'Edit' button. Paste the following code: if (event.value) event.value = event.value.substr(-12);

4
Save and Test

Click 'OK' to close the JavaScript editor, then close the Properties dialog. Exit form editing mode and test by scanning a barcode into the field.

Apply a Custom Calculation Script to the Destination Field
Handling Multiple Carriers: If you process tracking numbers from multiple carriers (like FedEx Express vs. FedEx Ground), you may need to expand the script with conditional logic to inspect the barcode prefixes before trimming.
Manage PDF Forms Effectively

Create and Edit PDF Forms with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to create interactive forms, add text fields, and customize document properties easily. It is a lightweight and cost-effective solution for all your professional document needs.

  1. 1. Open the PDF File: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available interactive form controls.
  3. 3. Edit Text Fields: Click on 'Text Field' to add a new input area, or double-click an existing field to modify its properties and formatting.
  4. 4. Save the Form: Once your fields are configured, click 'Save' to finalize your interactive PDF form.
Easily insert and edit interactive form fields in your PDFs.Fully compatible with standard Adobe PDF document formats.Lightweight software with a user-friendly, familiar interface.All-in-one suite to manage Word, Excel, PowerPoint, and PDF files seamlessly.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the scanned barcode not trim automatically after scanning?

If the scanner does not send an 'Enter' or 'Tab' keystroke at the end of the scan, the calculation field event might not trigger. You may need to configure your scanner hardware to add a carriage return suffix.

How can I change the script to keep the first 12 digits instead?

To retain the beginning of the barcode string instead of the end, change the JavaScript substring function to event.value = event.value.substr(0, 12);

Can I use this script for barcodes longer than 34 digits?

Yes, the substr(-12) function strictly counts backward from the end of the string. Regardless of whether the original barcode is 20, 34, or 50 characters long, it will reliably output only the last 12 digits.

Will this script affect manually typed entries in the form field?

Yes. Because the script runs on the field's calculation event, manually typing a value and pressing Enter or clicking away will also trigger the script and automatically trim the typed text to the last 12 characters.