PDF Editing Issues

How to Build a Two-Dimensional Array in an Acrobat Form

Jason MillerJason Miller Nov 3, 2026 868 views

Question details

The user needs to convert a delimited CSV string stored in a hidden form field into a functional two-dimensional array using JavaScript.

How to Build a Two-Dimensional JavaScript Array in an Acrobat Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Loading CSV data into a PDF form and parsing it using custom JavaScript to handle row and column data effectively.
Observed behavior
When accessing the array using double indices (e.g., matrix[0][0]), the script returns individual characters instead of the complete string values.
Before you start

Ensure you have access to the PDF form's JavaScript editor and verify that the delimiter used in your CSV string exactly matches the one in your script (e.g., semicolons or commas).

Solution 1Recommended

Split Strings into Arrays Before Pushing to the Matrix

Use the JavaScript split() method twice—once for rows and once for columns—to properly populate your two-dimensional matrix array.

When a single string is pushed directly into an array, indexing it twice will target the characters of the string. To fix this, you must split the row string into an array of values before adding it to your main matrix.

1
Retrieve and split the rows

First, extract the value from your hidden field and split it by the carriage return delimiter: var getData = this.getField('data_lijst').value.split('\r');

2
Initialize the matrix array

Create an empty array to hold your parsed two-dimensional data: var matrix = [];

3
Loop through rows and split by columns

Iterate over the rows and split each string by its column delimiter (like a semicolon) before pushing: for (var i = 0; i < getData.length; i++) { matrix.push(getData[i].split(';')); }

4
Access your data correctly

You can now retrieve the full string value using matrix[0][0] without it returning a single character.

Split Strings into Arrays Before Pushing to the Matrix
Proper Data Structuring: By splitting the inner string into an array before pushing it, JavaScript correctly recognizes it as an array of strings rather than treating it as a single flat string.
Powerful PDF Editing

Manage Interactive PDF Forms Easily with WPS Office

If you are working with complex PDFs and need an efficient, user-friendly tool, WPS Office offers a comprehensive PDF editor. It simplifies the process of viewing, filling, and managing interactive PDF forms without requiring complex custom scripting for everyday tasks.

  1. 1. Open your PDF document: Launch WPS Office and open your interactive PDF file using the built-in WPS PDF tool.
  2. 2. Access form fields: Click on any active form field to immediately begin typing or selecting dropdown values.
  3. 3. Edit PDF text and objects: Navigate to the Edit tab if you need to modify the surrounding document text, images, or layout.
  4. 4. Save or export data: Once your data is entered, easily save the completed form or export the document as needed.
Intuitive interface for filling and managing PDF forms.Highly compatible with standard Adobe Acrobat PDF formats.Lightweight, fast, and available across Windows, Mac, and mobile platforms.Includes an extensive suite of PDF tools, from editing text to merging documents.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my JavaScript array return a single character instead of a full word?

If you push a flat string into an array and try to index it twice (e.g., matrix[0][0]), JavaScript treats the string as an array of characters. You must split the string into a new array of individual words before pushing it into the matrix.

How do I extract data from a hidden field in a PDF form?

You can use the Acrobat JavaScript API method 'this.getField("FieldName").value' to retrieve the text stored in any form field, including hidden ones, for use in your background scripts.

Can I use standard JavaScript methods like split() and push() inside PDF forms?

Yes, PDF forms support a core subset of standard JavaScript, including common string manipulation methods and array functions, along with specific Adobe APIs for interacting with the document.