Skip to main content

Update on PDF Form Issues in ColdFusion

I posted previously on an odd problem I've run into with PDF forms populated by CFPDFFORM on ColdFusion 8 and the resultant PDF not being searchable via Ctrl-F in a PDF reader. Initially I thought it was a font encoding problem since I found some promising evidence to support that notion, so after spending literally an entire day changing hundreds of font encoding settings in PDF form fields individually in Acrobat (because you can't select them all and change them globally ... nice feature to add to Acrobat 10 maybe? YA THINK?), I thought I had the problem licked. I was able to open the PDF form in Acrobat, fill in the form field, save the PDF, and have the text I typed into the form field come up in searches.

Wrong. Turns out the only reason it was searchable was that I manually typed into the form field. When ColdFusion 8 populates the form fields with CFPDFFORM the form field still isn't searchable. Same problem with ColdFusion 9.

I submitted the issue to Adobe Support Center of Excellence, and a week and a half later they're saying they can reproduce the issue and it's getting escalated.

Since I have no clue when I'll get a response from Adobe and I'm putting my money on a "can't/won't fix" response (based on previous experience), this afternoon I grabbed the latest version of iText which is an open source Java PDF library. Among the numerous open source libraries bundled into ColdFusion, iText is one that's potentially used to power CFPDFFORM. (I'm not saying this is what's used since I can't know that for sure; I'm just saying it's a likely candidate if they didn't roll something themselves.)

Anyway, with iText in hand I wrote a simple little Java application to populate said PDF form. This way I could narrow down further if the problem is with iText (if that is in fact what ColdFusion uses for CFPDFFORM) or if it's something ColdFusion is doing that's causing the issue.

The result? iText by itself works perfectly. So at least now I have it narrowed down to ColdFusion being the culprit. I even replaced the iText instance in ColdFusion with the latest version to make sure that wasn't the issue, and either the version doesn't matter or iText is not in fact what ColdFusion is using to populate PDF forms.

You might be thinking, "But isn't CFPDFFORM so much simpler than Java?" Short answer is absolutely not . Longer answer is absolutely not and holy crap is using iText directly fast as hell.

Here's some simple CFML code that populates a PDF form:


<cfpdfform action="populate" source="mypdfform.pdf" destination="filledpdfform.pdf">
    <cfpdfformparam name="myPDFField" value="Foo" />
    <cfpdfformparam name="myOtherPDFField" value="Bar" />
    ... etc. ...
</cfpdfform>

<!--- now if you want the data in the pdf form to actually be saved to disk,
        you have to do this little dance to flatten it --->
<cfpdf action="read" source="filledpdfform.pdf" name="myPDFData" />
<cfpdf action="write" source="myPDFData" destination="filledpdfform.pdf" flatten="true" overwrite="true" />

And here's that same thing in Java--all I'm leaving out is some import statements that would be at the top of the class in which this code resides:


PdfReader reader = new PdfReader("mypdfform.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("filledpdfform.pdf"));
AcroFields form = stamper.getAcroFields();

form.setField("myPDFField", "Foo");
form.setField("myOtherPDFField", "Bar");
... etc. ...

stamper.close();

As you can see, the Java code is about the same as the CFML code. You open the PDF form, you set the field values, and you write the file out, although with iText I don't have to write/read/write again to get it flattened, which is one of my earlier "can't/won't fix" responses from Adobe.

What's my next step in all of this? Well, I'm faced with a pretty easy decision really. This is for an application the sole purpose of which is to process mountains of XML and generate flattened PDF forms containing the data extracted from XML. iText lets people actually search the PDFs as they should be able to (which is important since some of these PDFs are hundreds of pages long), iText is incredibly fast at cranking out PDFs in my limited testing thus far (which will be important when I'm re-generating three years of PDFs since none of the existing ones are searchable), and the Java code to achieve a better end result isn't any more complex than the CFML code.

It's an easy decision to use iText for this portion of the application. But as you can glean from the tone of this post I'm annoyed. CF 8 was new when this app was first built and one of the reasons we bought another CF 8 Enterprise license (since this app runs on its own server) was for this very feature because I figured it would be easier than using iText. It might have saved me some time initially, but boy am I paying dearly for it now.

So I'll start by reworking the PDF generation portion of the app to use iText, and then I'm going to start implementing CFPDFFORM in Open BlueDragon. Frankly given that there's literally no user interface for this application CF wasn't a great choice to begin with, but at the point when I was making the decision CFPDFFORM is what sold me on using CF instead of writing the app in Java. But three years later, here I am. My other option I'm pondering is rewriting the entire application in Java or Groovy since that's probably better suited to the no-UI aspects of the app anyway.

Nothing like having an itch to scratch to get motivated I guess, so at least the problems I'm having may lead to a nice new (and fully working!) feature in Open BlueDragon at some point, and maybe I'll dig into Groovy more to rewrite my existing app. Interesting times ahead.

Comments

Anonymous said…
Good example of the K.I.S.S. principle at work. Somewhere along the way every continuing, evolving "project" has this happen. It happens in computer programs, home improvement, and government. The "designers" inevitably add so much to their "project" that it ceases to function in the way it was originally designed or achieve the orignal intended purpose. When this happens, and the "designers" are too invested in the "project" to allow it to "get back to basics" then often times the only solution is to chuck the whole thing and start something new.I apologize if I am waxing too metaphorical.Glad you were able to make your own solution, Matt. I hope it means better days ahead for you with this project.
Matthew Woodward said…
Update on the update--it's officially a bug, and Adobe's workaround is to ... wait for it ... use iText. Maybe it'll work properly when CF 10 comes out.
YouthPastor said…
CF10 is available in beta and still apparently using iText 2.1.0 from 2008. Are you able to install the developer version and see whether this issue persists?

Here's the current ColdFusion bug database:
https://bugbase.adobe.com/
Matt Woodward said…
Since I don't use Adobe CF anymore I don't really have a need to test it. :-) Hopefully they got it resolved.
Reynaldo Rivas said…
Hi. This service here allows you to easily edit your PDF documents.
http://goo.gl/wdh5gV

You can fill out PDF form, save it, fax it, and email it.
Lacy Brown said…
Adobe is one of the most popular graphics/images editing applications, with excellent features, if you have any issues for adope ,our company provide online help and support for adope.
Adobe Support

Popular posts from this blog

Installing and Configuring NextPVR as a Replacement for Windows Media Center

If you follow me on Google+ you'll know I had a recent rant about Windows Media Center, which after running fine for about a year suddenly decided as of January 29 it was done downloading the program guide and by extension was therefore done recording any TV shows.

I'll spare you more ranting and simply say that none of the suggestions I got (which I appreciate!) worked, and rather than spending more time figuring out why, I decided to try something different.

NextPVR is an awesome free (as in beer, not as in freedom unfortunately ...) PVR application for Windows that with a little bit of tweaking handily replaced Windows Media Center. It can even download guide data, which is apparently something WMC no longer feels like doing.

Background I wound up going down this road in a rather circuitous way. My initial goal for the weekend project was to get Raspbmc running on one of my Raspberry Pis. The latest version of XBMC has PVR functionality so I was anxious to try that out as a …

Setting Up Django On a Raspberry Pi

This past weekend I finally got a chance to set up one of my two Raspberry Pis to use as a Django server so I thought I'd share the steps I went through both to save someone else attempting to do this some time as well as get any feedback in case there are different/better ways to do any of this.

I'm running this from my house (URL forthcoming once I get the real Django app finalized and put on the Raspberry Pi) using dyndns.org. I don't cover that aspect of things in this post but I'm happy to write that up as well if people are interested.

General Comments and Assumptions

Using latest Raspbian “wheezy” distro as of 1/19/2013 (http://www.raspberrypi.org/downloads)We’lll be using Nginx (http://nginx.org) as the web server/proxy and Gunicorn (http://gunicorn.org) as the WSGI serverI used http://www.apreche.net/complete-single-server-django-stack-tutorial/ heavily as I was creating this, so many thanks to the author of that tutorial. If you’re looking for more details on …

The Definitive Guide to CouchDB Authentication and Security

With a bold title like that I suppose I should clarify a bit. I finally got frustrated enough with all the disparate and seemingly incomplete information on this topic to want to gather everything I know about this topic into a single place, both so I have it for my own reference but also in the hopes that it will help others.Since CouchDB is just an HTTP resource and can be secured at that level along the same lines as you'd secure any HTTP resource, I should also point out that I will not be covering things like putting a proxy in front of CouchDB, using SSL with CouchDB, or anything along those lines. This post is strictly limited to how authentication and security work within CouchDB itself.CouchDB security is powerful and granular but frankly it's also a bit quirky and counterintuitive. What I'm outlining here is my understanding of all of this after taking several runs at it, reading everything I could find on the Internet (yes, the whole Internet!), and a great deal…