How to Build a Two-Dimensional Array in an Acrobat Form
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.

- 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.
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).
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.
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');
Create an empty array to hold your parsed two-dimensional data: var matrix = [];
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(';')); }
You can now retrieve the full string value using matrix[0][0] without it returning a single character.

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. Open your PDF document: Launch WPS Office and open your interactive PDF file using the built-in WPS PDF tool.
- 2. Access form fields: Click on any active form field to immediately begin typing or selecting dropdown values.
- 3. Edit PDF text and objects: Navigate to the Edit tab if you need to modify the surrounding document text, images, or layout.
- 4. Save or export data: Once your data is entered, easily save the completed form or export the document as needed.

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.




