Back 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. a mail merge type application).

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. 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. Let’s do a simple example with a small table:

Firstname

Lastname

John

Doe

Jane

Doe

The data in the PDF file would be organized like this:

Firstname_1

Lastname_1

Firstname_2

Lastname_2

Our datafile would then look like this:

Firstname_1 Lastname_1 Firstname_2 Lastname_2
John Doe Jane Doe

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.

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. It can certainly be done, especially if a VBA macro is used, but it’s not what I would do.

The good news is that this can still be done using JavaScript. 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. This way, we can read one record at a time, and then copy that record into our final form. This temporary form will be created on the fly using JavaScript. 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. In my example further down, I am placing all fields right on top of each other.

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:

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. There cannot be any extra fields either. And, in this particular case, you will have to make sure that you only import up to the same number of records that your document can actually handle. My document uses 20 records, so I am checking for that in my script. If you need continuation pages, you can certainly do that, it would make the script a bit more complex.

If you want to adapt this approach for your own solution, make sure that you add all required fields to your temporary document. In the example above, I am only using text fields, but the same technique can be used for other field types as well.

Guillermo, without having access to your system, it’s impossible to say what’s wrong. Is this on a Mac? If not, you need something like this: “/c/Users/usuario/Desktop/…” – The driver letter needs to be part of the path.

I have accomplished the merge with a single row of data however, my excel data is 400 rows long and I like a single PDF sheet for each row printed. I understand that the JavaScript needs to be added however, I am using Adobe Pro X and I’m not exactly sure where in Adobe Pro I will be including the JavaScript. Also, when I am prompted to select a row to merge, will this still be necessary and will it prompt itself to continue to the last row of data. Please forgive my lack of understand and your assistance is greatly appreciate.

Sharon, Adobe Acrobat X Pro does not have custom commands, so you would need a menu item to launch the script, or use an Action (created via the Action Wizard) that will execute your script. For a menu item, you would need to modify the script, but it should work without modifications as an Action. You may want to play around with just the script and the data from this blog post until you have it working, and then move to your own form and data.

app is undefined when i ran the script.
This is issue might be because i am not able to install AcroXIPIWizInstaller and Visual Studio App Wizard provided in the tools folder of adobe SDK.
It is showing an error that i can be installed on VS2008 / VS2013 and not support provided for VS2012(i am using 2012).

You are mixing two different things: “app” is an object in the JavaScript API, Visual Studio and the plug-in wizard are required to create plug-ins for Acrobat. These are two completely different APIs, and you cannot mix and match features and objects between the two. What exactly are you trying to do, what is your script, and what is the error message you are receiving?

I have a data table returned from the code and i want to show that data in the Acrobat PDF file in table form. When i use the above script, i am getting error on line
app.newDoc() i.e. app is not defined.

Is it possible to import data from a CSV or Tab Delimited Text File and have it populate a Form 941 and Form Schedule B for the 941 from the IRS? The forms are in the same format for the duration of a year. If I’m trying to use Virtual Basic/Macros is there a way I could write a script to populate these fields? I have 50+ Companies I have to fill this form out. The data is already in individual CSV files for each company….However I have to manually copy and paste it into every field for over 50 companies! So time consuming. There must be a way if the data is already there.

tinchox5, most problems are usually related to a mismatch in the columns in the data file vs. the fields in the document. The number has to be the same, and the column headers need to match the field names in the form.

Thank you for your reply. I am still having a question that seeks some suggestions.

In the link of “Batch-Import list data into pdf form”, I can understand that in the code part, it is to create a temporary document to store the data from txt file. But I can not find how to import that existed pdf “sign-in sheet” and how to generate that pdf form to be ready to download. I mean, how to get this generated pdf “sign-in sheet”, I am a little bit confused because I am still a beginner for javascript currently.

Changjian, when you look at the code, you will see the “this” keyword: This indicates that the code is operating on the currently open PDF file in Acrobat. So, you would open your form, and then run the script.

Thanks so much for making this post – it’s exactly what I need to get something that takes to take a team of 3 people 2 days to manually key in (and hopefully, if I solve my issue) that could take them 2 minutes instead.

My issue – I built a form based on this post, and tested it a few weeks ago in preparation for a deadline I have coming up, and with my test data everything worked fine – but then I built the form out more, to include fields that users will provide input on, based on the data I planned on importing that I’ll be providing to the users.

I keep getting the ‘missing data’ error now that I’m attempting to load actual data – and I think it’s because I have the fields that are meant to be blank in the form and therfore have no data in the dataset that’s feeding them.

What’s the best way to script in something that basically says ‘fill all the fields in that you have, and skip the fields that don’t exist in the dataset, and then move on to the next line of data for the next form’?

Ankit, if you want to use the built-in function to import data, then you have to make sure that every field in the PDF file is reflected in your data file. You cannot have missing columns. If you need a solution that works with a mismatch between fields and data, I would use e.g. a VBA program to remote control Acrobat and add only fill fields that need data. That is a completely different approach and not as simple as what I’ve demonstrated in this blog post.

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Tip Jar

If the information you found on my site helped you to solve a problem, please consider to hire me for your next PDF related project. If you just want to say “Thank You” for the tips and tricks I provided, you can leave a tip via PayPal (starting at $1):