PDF form population with iText
iText is a powerful library that allows user to create and manipulate PDF files. Currently there are Java and .NET version of the library which proves to be one of the most popular tools for PDFs. Often used as part of web applications for generation of output for forms and document generation automation iText is free for use under the AGPL open source license. Keep in mind that this is not an end user utility but rather a developer tool for integration in applications and APIs.
In this example I will present the reader with a simple way of using iText for form fill automation. A simple example of how this comes useful is when a user fills information in a web form or a series of forms (as part of a workflow) and at the end is presented with an option to save or print a summary or an agreement. In this situation it is very useful to present the user with an opportunity to use Adobe’s PDF format in addition to plain HTML.
In order to proceed with the execution you will need the latest iText jar which you can find here. In addition you will have to have or create a PDF form which will be used in the automated form completion process. For the purposes of this example I have created a very simple form using Adobe Acrobat Professional which has just 2 simple fields: first name and last name. You can download the form used in this example Form. The two form fields are called FirstName and LastName. Next we can use the following java code to load the template, extract the form, and fill the desired information in the fields:
// get the destination
String location = "C:/java/pdf/src/";
if (location != null && !location.endsWith(File.separator))
{
location = location + File.separator;
}
PdfReader reader = new PdfReader(location + "Form.pdf");
String name = "Output.pdf";
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(location + name));
AcroFields form = stamp.getAcroFields();
String last = "subform[0].LastName[0]";
String first = "subform[0].FirstName[0]";
form.setField(last, "HRISTOV");
form.setField(first, "NEDKO");
// close pdf stamper
stamp.setFormFlattening(true);
stamp.close();
reader.close();
The snippet above creates a file called Output.pdf and fills the text values in. In addition to simple textboxes you can have checkboxes, number fields, dropdowns, fields with format validation like phone numbers, social security numbers, barcodes etc. In the next example I provide a more complex form with different types of fields.


Google Apps is a service providing customized solution for your company using several of Google’s products. By using Google Apps for your domain you can take advantage of Google’s mail service (Gmail) as well as several web applications including Google Calendar, Google Docs, Google Talk. Since Gmail now supports both POP and IMAP functionality it’s worth considering switching your in-house email solution to Google Apps and offload the need for hardware, software, administration and maintenance, backups etc. For those of you who are already thinking about it – keep reading.
Let’s see how we can use some simple tools and create a functional example of how multipart MIME actually works in practice. With both of my hands in the carburetor (a car repair term for getting down to business and having things done fast) I sit down and get busy with creating the necessary form and php script. Before I get into more details I want to make clear that you will need PHP set up correctly. For the purposes of creating something interactive we’ll use our code in the context of an Apache 2 web server which will make testing and using the application easier.