How to Populate a PDF Text Box from a CSV File Using JavaScript
Question details
The user wants to automate the process of creating text boxes in multiple PDF documents, stamping them with their filenames, and populating them with matching text from an external CSV file.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Batch processing hundreds of PDF documents to stamp and insert matching text from a CSV database based on the PDF filename.
- Observed behavior
- Needs a scripted method to read a CSV file, parse the data into a model, match the current PDF filename with the CSV rows, and automatically insert the corresponding text into the PDF form fields.
Ensure that your PDF software has the necessary permissions to execute JavaScript and read external files, as most modern PDF readers block local file access by default for security reasons.
Write a Custom Acrobat JavaScript to Parse CSV Data
Use a custom JavaScript script within your PDF editor to read the CSV file, match the document's filename, and fill the target text box field.
Automating PDF form filling from an external CSV requires writing a JavaScript routine. The script must know the CSV file path, parse its contents into an internal data array, check the current PDF filename against the data, and update the form field accordingly.
Determine whether the file path will be hard-coded into your script or if you want the script to prompt the user to select the CSV file each time the automation runs.
Open your PDF document, navigate to the Form editing tools, and create a new text box or text field. Assign it a specific name (e.g., 'DataField') so the script can locate it.
Open the JavaScript console or document-level script settings. Write a script that uses file reading methods (like util.readFileIntoStream) to load the CSV data into memory.
Program the script to split the CSV data by rows and commas. Retrieve the current document's filename using 'this.documentFileName', find the matching row in your parsed array, and extract the required text.
Use the command 'this.getField("DataField").value = matchedText;' within your script to insert the retrieved text into the designated PDF text box.

Try WPS Office for Your Daily PDF and Document Needs
While advanced JavaScript coding for external CSV parsing is highly specific to professional scripting environments, WPS Office provides an incredibly user-friendly suite for everyday PDF editing, form filling, and document management without a steep learning curve.
- 1. Download and Install WPS Office: Get the free application from the official WPS website, install it on your device, and open your PDF document.
- 2. Access the Edit Tab: Navigate to the 'Edit' tab in WPS PDF to modify existing text, add new text boxes, or adjust formatting.
- 3. Fill PDF Forms Easily: Use the built-in form tools to manually type into text fields, check boxes, and interact with form elements, then save the document securely.

Frequently Asked Questions
Can I batch populate PDF forms from a CSV without using JavaScript?
Yes, you can use the built-in Mail Merge features in word processors like Microsoft Word or WPS Writer to generate multiple documents from a CSV data source, and then export those finalized documents as PDFs.
Why is my Acrobat JavaScript failing to read the CSV file?
JavaScript execution in modern PDF viewers is heavily sandboxed. Reading local file paths directly is often blocked by security policies. You usually need to create folder-level trusted scripts to bypass these restrictions and allow local file access.
Is there a simpler way to stamp PDFs with their filenames?
Yes. Many PDF editors and batch processing tools have dedicated 'Bates Numbering' or 'Header & Footer' features that allow you to automatically insert the document's filename into the header or footer without writing custom code.




