Other PDF Issues

How to Read and Write CSV or TXT Files Using Acrobat JavaScript in PDFs

Adam DavisAdam Davis Nov 5, 2026 868 views

Question details

The user wants to use Acrobat JavaScript to read data like invoice numbers from a local CSV or TXT file, and then write updated invoice data back to that file when creating a new PDF invoice.

How to Read and Write CSV or TXT Files with Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Generating a new invoice in a PDF form and needing to automatically retrieve the latest invoice number from an external CSV/TXT file, then saving the new entry.
Observed behavior
The user encounters strict security limitations, as JavaScript within a PDF cannot freely read or modify local files without configuring privileged folder permissions or using external tools.
Before you start

Ensure you have access to the local file paths you intend to read, and verify you have administrative permissions to configure folder-level trusted scripts in your PDF application's installation directory.

Solution 1Recommended

Read Local CSV Files Using util.readFileIntoStream

Use Acrobat JavaScript's utility method to read the contents of a local CSV or TXT file as a stream via a trusted function.

Acrobat JavaScript provides the `util.readFileIntoStream` method to read local files. However, due to strict sandbox security measures designed to protect users from malicious scripts, this method cannot be executed from a standard document-level script. It requires the script to be executed from a privileged context, meaning you must set up a trusted function within a folder-level script.

1
Locate the Application JavaScripts Folder

Open your file explorer and navigate to your Acrobat installation directory (e.g., C:\Program Files\Adobe\Acrobat DC\Acrobat\JavaScripts) to find the privileged folder.

2
Create a Trusted Function File

Use a text editor to create a new '.js' file in this directory. Define a trusted function using 'app.trustedFunction' to safely wrap the file-reading command, allowing it to bypass standard security prompts.

3
Implement util.readFileIntoStream

Inside the trusted function, write the command 'util.readFileIntoStream()' passing your CSV's local file path. Convert the returned stream into a string to parse your invoice numbers and dates.

4
Call the Function in Your PDF Form

Open your PDF, navigate to 'Prepare Form', and insert a button. Under the button's Action properties, add a JavaScript action that calls your newly created trusted function to populate the invoice fields.

Read Local CSV Files Using util.readFileIntoStream
Writing Limitations: JavaScript alone cannot freely write or add new columns directly back into the local CSV file. Modifying the file requires external specialized tools or server-side processing.
Free Microsoft Office alternative

Manage Invoices, PDFs, and CSVs with WPS Office

Scripting automated data connections between PDF forms and local CSV files requires complex programming, trusted functions, and security workarounds. Instead of struggling with Acrobat JavaScript, you can streamline your workflow by managing your invoice database directly in a powerful spreadsheet. WPS Office is a lightweight, all-in-one suite that lets you handle Word, Excel, PDF, and CSV files seamlessly—all without writing a single line of code.

  1. 1. Download the Software: Visit the official WPS Office website and click the Free Download button for your operating system.
  2. 2. Install the Suite: Run the downloaded installation file and follow the on-screen prompts to set up the software on your computer.
  3. 3. Open Your Files Seamlessly: Launch WPS Office and drag your CSV, TXT, or PDF invoice files directly into the workspace to start managing them instantly with zero complex configurations.
Fully compatible with Microsoft Office formats, ensuring seamless handling of CSV, TXT, and XLSX files.Built-in PDF reader and editor for straightforward document management without complex scripting.Lightweight application with a familiar UI, making migration quick and effortless.Free to use for everyday document, spreadsheet, and presentation tasks.
microsoft office alternative - wps office

Frequently Asked Questions

Can Acrobat JavaScript directly add a new column or modify an existing local CSV file?

No. Acrobat JavaScript operates within a strict security sandbox and cannot natively write to or modify local CSV or TXT files directly. To update the file, you must submit the form data to a server-side script or use an external application.

What is the util.readFileIntoStream method?

It is an Acrobat JavaScript utility used to read the contents of a local file and return it as a data stream. Because this action accesses the local file system, it requires elevated privileges to execute without triggering security warnings.

How do I bypass the security warnings when reading local files in Acrobat?

You must create a 'trusted function' by placing a custom JavaScript file (.js) into the application-level JavaScripts folder on your computer. Functions defined this way can safely execute privileged commands like util.readFileIntoStream.

Is there an easier way to manage incremental invoice numbers?

Yes. Instead of using complex PDF JavaScript to link a form to a local CSV, it is often simpler to maintain your invoice database in a spreadsheet application like Excel or WPS Spreadsheet, and use mail merge or built-in templates to generate your PDFs automatically.