Auto-Import Matching Row from Text File to Acrobat PDF Form
Question details
The user wants to automate the process of importing specific rows of data from a large tab-delimited text file into a PDF form based on an entered part number.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Populating a PDF form automatically by matching an entered part number with the corresponding data row from an external tab-delimited text file.
- Observed behavior
- Users currently have to manually locate and select the correct part number from the large text file to import the matching data into the PDF form.
Ensure you have access to the tab-delimited text file containing your data and have Adobe Acrobat Pro installed, as standard PDF readers do not support advanced JavaScript data manipulation.
Write Acrobat JavaScript to Parse the Text File
Utilize Acrobat's custom JavaScript capabilities to open the text file, search for the entered part number, and populate the corresponding form fields.
The doc.importTextData() method built into Acrobat requires a specific row number to import data. To bypass manual row selection, you can write a custom script that reads the text file, loops through the rows to find a matching part number, and extracts the necessary values to assign them directly to your form fields.
Open your PDF form in Adobe Acrobat Pro, go to the 'Tools' menu, and select 'Prepare Form'.
Right-click the Part Number text field (or the field where you will enter the lookup value) and select 'Properties'.
Navigate to the 'Actions' tab, select 'On Blur' or 'Key Stroke' as the trigger, and choose 'Run a custom JavaScript' from the action dropdown. Click 'Add'.
In the JavaScript editor, write a script that utilizes util.readFileIntoStream() to load the tab-delimited text file, splits the content by line breaks to iterate through the data rows, and locates the row containing the matching part number.
Once the matching row is identified, split that row by tabs to extract individual column values and use this.getField("FieldName").value = extractedValue to populate the remaining fields in your PDF.

Implement Third-Party PDF Scripting Tools
If you are not comfortable writing custom JavaScript from scratch, utilize existing paid scripts and add-ons designed to populate PDF fields automatically.
Handle Bulk Data and Generate Filled Forms with WPS Office
Instead of writing complex JavaScript to pull text file rows into a PDF form, you can use WPS Spreadsheet to manage your tab-delimited data and WPS Writer's Mail Merge feature to automatically generate filled forms or PDFs in batches without any coding.
- 1. Organize Data in WPS Spreadsheet: Open WPS Spreadsheet and import your large tab-delimited text file to view and manage the data in an organized table format.
- 2. Prepare the Form in WPS Writer: Open WPS Writer and design your form layout, or open an existing Word/PDF-based form template.
- 3. Link the Data Source: Go to the 'Mailings' tab, click 'Open Data Source', and link the saved Spreadsheet file containing your part numbers and related data.
- 4. Insert Merge Fields: Click 'Insert Merge Field' and place the appropriate data fields into the specific areas of your form where the details need to appear.
- 5. Merge to PDF: Click 'Merge to New Document' or select 'Export to PDF' to automatically generate individual, perfectly populated forms based on your specific data rows.

Frequently Asked Questions
Why doesn't the Acrobat doc.importTextData() method work without a row number?
The built-in doc.importTextData() function in Adobe Acrobat is strictly designed to import a specific, known row index from a text file. It does not have native search or lookup capabilities, which is why custom JavaScript is needed to find the matching row first.
Can I populate a PDF form directly from an Excel file instead of a text file?
Direct extraction from an Excel spreadsheet (.xlsx) via JavaScript in Acrobat is highly restricted and technically complex. Excel files must typically be saved as tab-delimited text or CSV files first, which can then be parsed by scripts.
Are there security restrictions when reading local text files via PDF scripts?
Yes, Adobe Acrobat applies strict security restrictions to JavaScript operations that read local files to prevent malicious activity. Your custom script must be executed in a privileged context, such as being installed in the application's local JavaScript folder, or the document itself must be certified.




