Skip to main content

Porting a CFPDF / CFPDFFORM-Dependent Application to Open BlueDragon

In my continuing war against all things PDF in ColdFusion, today I believe I have achieved victory.

If you've been following my posts (OK, rants) over the past few weeks you'll know that I ran into some annoying bugs in CFPDFFORM that were wreaking all sorts of havoc with the one application I wrote that depends on CFPDFFORM for a key part of what it does. I sent my test case to Adobe Support and, well, there are probably a million ways to couch this nicely, but the bottom line is they told me they can't/won't fix the bug, and their suggested workaround was to use iText to populate my PDF forms instead of using CFPDFFORM. Given that I ran into another annoying bug with CFPDFFORM a couple of years ago and got another "can't/won't fix" answer, this was strike two for CFPDFFORM. And personally I don't like being backed into a corner by a third strike before making a change.

Now that my CFPDFFORM code had been changed over to use iText instead (which gave some nice speed benefits as well), the only remaining thing keeping me tied to ColdFusion 8 was the use of CFPDF to merge multiple PDFs into a single file. I looked into doing this with iText and although it's doable, even being the gearhead I am I have to admit that's a bit of a hassle. So before implementing that solution I decided to hunt around a bit more.

Enter Apache PDFBox.

PDFBox is already bundled with Open BlueDragon since we use it as the underlying libraries for some CFDOCUMENT functionality, but it's a version behind the absolute latest. Turns out that the newest version of PDFBox has a great, easy-to-use PDFMergeUtility built in. This made removing my dependence on CFPDF (which isn't in Open BlueDragon yet) pretty simple.

My application populates a varying number of individual PDF pages and then merges these pages into a single PDF file at the end of processing. So I use an "assembly" directory to build up the individual pages of the final result, and the final step is to merge the files. Previously I was using CFPDF for this:


<cfpdf action="merge"
       source="#filesToMerge#"
       destination="#destDir##destFileName#.pdf"
       overwrite="true" />

And the PDFBox PDFMergeUtility solution looks like this:


<cfset pdfMerger = CreateObject("java", "org.apache.pdfbox.util.PDFMergerUtility").init() />

<cfloop list="#filesToMerge#" index="fileToMerge">
  <cfset pdfMerger.addSource(fileToMerge) />
</cfloop>

<cfset pdfMerger.setDestinationFilename("#destDir##destFileName#.pdf") />
<cfset pdfMerger.mergeDocuments() />

So it's a few more lines of code, but honestly not bad at all compared to the CFPDF version, and if you've been looking for ways to do some of what CFPDF and CFPDFFORM do in CF 8, between iText and PDFBox it looks like you're covered.

I was forced to make the switch from CFPDFFORM to iText in order to get around a bug in CFPDFFORM, and with that out of the way it was only one more step to make this application CFML engine agnostic. I need to do some additional testing but with the CF 8 dependencies removed the app is running great on Open BlueDragon. I'll do some comparison metrics but in initial testing, particularly since this is a CFC-heavy application, the speed and CPU load are both dramatically improved. Speed is about 30-50% faster (which makes a BIG difference when this app runs processing for hours at a time), CPU utilization is about half (CF completely pegs the CPU while this app is in full processing mode), and it's noticeably lighter on RAM as well. All told the minor hassle of reworking these portions of the app will have been well worth it.

Comments

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 …

Running a Django Application on Windows Server 2012 with IIS

This is a first for me since under normal circumstances we run all our Django applications on Linux with Nginx, but we're in the process of developing an application for another department and due to the requirements around this project, we'll be handing the code off to them to deploy. They don't have any experience with Linux or web servers other than IIS, so I recently took up the challenge of figuring out how to run Django applications on Windows Server 2012 with IIS.

Based on the dated or complete lack of information around this I'm assuming it's not something that's very common in the wild, so I thought I'd share what I came up with in case others need to do this.


This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Assumptions and CaveatsThe operating system is Windows Server 2012 R2, 64-bit. If another variant of the operating system is being used, these instructions may not work properly.All of the soft…

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 …