May 12 2011

Just as there are trends in business, one of the trends I keep seeing in business processes is the need to automatically generate PDFs based on information gathered by the process.  In this, I'll step through how to have a process automatically generate customized PDFs that can be attached to instances and / or emailed to clients.

This recently came in handy on the project I'm rolling off of right now.  Because of regulatory requirements, my client needs to send their customers various PDF forms.  Even though my client already knew a lot about their customer, the forms were sent out completely blank for the customer to manually fill in.  Because customers were sent several forms to fill in at one time, they found themselves filling in the same information over and over again.  My client wanted to make it easier for their customers to do business with them and now send out the forms with many of the fields already filled in with information gathered upsteam in the process and from their database.  This means three important things to this business:

  1. The customer no longer had to repeatedly fill in information in the form that was already known by my client
  2. My client was able to have the customer easily verify that the information was correct
  3. Barcodes that specify the customer and the document type are now added to the documents.  As the documents are returned, they are scanned and automatically associated with the right customer and the their work item in the process.

When dealing with PDFs automatically generated by a process, I recommend that you take a PDF template approach. This template is just a normal PDF document that contains the fields I want to populate in the PDF.  There are tools that let you edit PDF documents and insert blank fields into a PDF template (Adobe Acrobat is one but there are other tools that also do this).  As I add the fields, I give each field a unique name (e.g. "customerName").  

sample PDF template with a label and field for the customer name

I use the PDF Java API developed by Bruno Lowagie called iText (http://itextpdf.com).   If you use Oracle BPM 10g, this API is enabled by adding the Jar file as an external resource.  In addition, I wrote a Java helper class that I invoke from the process.  My Java method takes a hashmap as an input argument and for each "key" value in the hashmap, inserts the name of the field in the template that I want to populate ("customerName" in the above sample).  The text or number to insert into each of the PDF template fields is passed in as the value in the hashmap.  Here's an example:

  myHashmap["customerName"] = someVariableSetInTheProcess;

The benefit of having a hashmap as an input argument is that this same Java method can be used to fill in information for any PDF template (even though the field names are different for each template).  Another argument to the Java method is the name and location of the PDF template.  The output is a generated PDF that has the field labels with their respective values filled in. 

this is the output after the PDF document is generated

Because the output is another PDF file, this file can then be attached to the instance or sent to the customer via email in the next activity in the process.

One last tip I'll pass on is about inserting barcodes.  Initially, I thought I could add barcodes using the same technique described here.  The problem you will have if you try doing this is that even though you change your field in the template to use a barcode font (e.g. barcode39) the recipient will still see the barcode as plain text instead of the barcode.  The reason this occurs is because even though you might have the barcode font on your machine, your recipients will almost never have a barcode39 font on their machines.  What I learned is that you can instead insert the barcode as an image into the PDF document using the iText API.

Here is the location of my Java helper code that that fills in PDF templates using the technique described here: 

Jacket.txt

About the Author

Dan Atwood

Dan has more than sixteen years of experience in all phases of design, development, and implementation of software applications using BPM. He has developed Oracle BPM, BAM, business rule and integration solutions for financial services, insurance, food cooperative, and telecommunications clients.

Join the Conversation

Enter your first name. It will only be used to display with your comment.
Enter your email. This will be used to validate you as a real user but will NOT be displayed with the comment.
By submitting this form, you accept the Mollom privacy policy.