There are a few potential problems when you are using this approach: First of all, the same limitations that apply to manually importing data apply here as well: You need to make sure that each column in your data file is represented by a field in your temporary file, and that the names match. Here is the sample file I’ve used as Excel Spreadsheet and as tab delimited text file (this is random data thanks to the “ Fake Name Generator“. we can only process 20 records on each sheet This.getField("Email" + (idx + 1)).value = email
This.getField("Name" + (idx + 1)).value = name // we need to adjust the index by one Var email = tmpDoc.getField("Email").value Var name = tmpDoc.getField("Lastname").value + ",\n" + collect the data and add it to the "real" form from the data file and then copy that data to the correspondingĮrr = tmpDoc.importTextData(dataFile, idx) // imports the next recordĪpp.alert("Warning: User Cancelled Row Select") Īpp.alert("Warning: User Cancelled File Select") Iterate over the data file and import the corresponding record TmpDoc.addField("Lastname", "text", 0, ) TmpDoc.addField("Firstname", "text", 0, ) that correspond with the three columns in our data file. Create a temporary document and add the three text fields Var dataFile = "/Users/username/data.txt" // !!! CHANGE THIS !!! * Import list data from tab delimited text file */ The following script can for example be used as an Action, or a custom command in Acrobat DC:
You can download the documents from these links:
Let’s assume we want to create a sign-in sheet for an event, and we want to print the full name of each participant and the participant’s email address on the form: In my example further down, I am placing all fields right on top of each other. And, because we will never actually look at that form, we don’t have to worry about placing the form fields in any meaningful way. This temporary form will be created on the fly using JavaScript. This way, we can read one record at a time, and then copy that record into our final form. The trick is to work with two documents: We of course start out with the document that we want to populate with data, but in addition to that, we are also using a temporary document that has one set of fields for each record we are going to read. The good news is that this can still be done using JavaScript. It can certainly be done, especially if a VBA macro is used, but it’s not what I would do. This is simple to do for a small files, but if you are dealing with 100 records of 10 fields each, we are talking about a pretty extensive row of data. The blank spaces between the entries in the list above are TAB characters – remember, we need a tab separated text file for this to work. Our datafile would then look like this: Firstname_1 Lastname_1ğirstname_2 Lastname_2
The data in the PDF file would be organized like this: Firstname_1 Let’s do a simple example with a small table: Firstname If we would use the method from above, the whole form data would have to be rewritten into a spreadsheet with just one row of data. What if we want to import rows of data into one document? Let’s assume, we have a table in our document with 20 rows, and we have a spreadsheet that has the same 20 rows, and we want to import that data. We’ve talked about batch importing data from an Excel document into a PDF form before: īack then, the idea was that we would have a spreadsheet with rows of data, and every row would be imported into a new copy of the document (e.g.