TerrenceRyan.com

I'm a 35 year old redhead geek from Philly.
I'm currently a Developer Evangelist for Adobe.
Also the author of Driving Technical Change

Entries for month: July 2008

Starting a New Job

So once again, I'm moving jobs. I'm still with the Wharton School. However, now I will be working for Knowledge@Wharton. I'll be working on small and medium sized projects, working on growing the backend platform, and anything else they tell me to do.

I'm pretty excited about the move. I'll be joining a great team, it gives me an opportunity to work for a former boss again, and it's a lot easier to point someone to a public site like Knowledge as an explanation of what I do.

I start Tuesday, after a visit to DC this weekend.

Unit Testing PDF Page Size in ColdFusion

I ran into a difficult Unit testing problem the other day. I had trouble determining the correct test to write, and finally did so. I thought that perhaps someone else might benefit from an exploration of testing strategy.

As you might know, we create pdf's using ColdFusion for ExportReports.com. One of the new features we are adding is the ability to set the page size (legal, letter, A4… etc.) As page size is a feature, I need to test it. So I need to create a pdf file then determine what its page size is. At first I explored <cfpdf> and its ability to get at PDF metadata. No joy - it turned out that page size isn't one of the things returned in the metadata. Then I looked at <cfpdf>'s ability to get thumbnails of the pages in the pdf. I could use <cfimage> to get the information about height and width of the image files, put that was in pixels and hard to translate to inches. (I tried assuming 300dpi, it did not yield good results.) Then it dawned on me that ratio of height to width could yield helpful answers. I found the dimensions in millimeters for the various page types, created ratios from them, and compared them to the ratio of the dimensions of the thumbnails. Then I had to correct a bit for precision, and it yielded me a solution. Here's what it looked like in code:

<!--- Grab a processable view of the pdf --->
<cfpdf action="thumbnail"
       source="#pdfQuery.directory#/#pdfQuery.name#"
      
destination="#dirreports#tn"
      
scale="100" overwrite="TRUE"/>

<cfdirectory action="list"
             name="thumbnailQuery"
            
directory="#dirreports#tn"
            
filter="*.jpg" />

<cfimage action="info"
         source="#thumbnailQuery.directory#/#thumbnailQuery.name#"
        
structName="pInfo">

<cfset assertTRUE(validatePaperSize(width=pInfo.width, height=pInfo.height, pageType='legal'))/>

<cffunction name="validatePaperSize" access="private" output="false" returntype="boolean" >
     <cfargument
name="width" type="string" required="yes" />
     <cfargument
name="height" type="string" required="yes" />
     <cfargument
name="pageType" type="string" required="yes" />

     <cfset var ratios = structNew() />
     <cfset
var ratioToTest = NumberFormat(height/width, "_.___") />

<!--- These ratios were derived by using sizes in millimeters
listed here: http://en.wikipedia.org/wiki/Paper_size --->

     <cfset ratios['letter'] = NumberFormat(279/216, "_.___") />
     <cfset ratios['legal'] = NumberFormat(356/216, "_.___") />
     <cfset ratios['A4'] = NumberFormat(297/210, "_.___") />
     <cfset ratios['A5'] = NumberFormat(210/148, "_.___") />
     <cfset ratios['B4'] = NumberFormat(353/250, "_.___") />
     <cfset ratios['B5'] = NumberFormat(250/176, "_.___") />

     <!--- Fudge precision --->
    
<cfif Abs(ratioToTest - ratios[arguments.pageType]) lt .005 >
    
     <cfreturn true />
    
<cfelse>
    
     <cfreturn false />
    
</cfif>    

</cffunction>

So it might not be perfect, but it works for me. Of course, I could just file a feature request with Adobe to add page size to PDF metadata.

Speaking at Max 2008

I found out last week, that I was accepted to speak at Max 2008 North America. I'll be talking about using ColdFusion to act as middleware for enterprise applications. That may not be clear from the title of my session: ColdFusion as Enterprise Middleware.

I'm pretty excited about the whole thing, and very grateful to the crew at Adobe, especially Adam Lehman, for giving me a shot to speak.

If anyone has any suggestions, or content they would like to hear about, feel free to drop me a line. I don't guarantee I'll do what you say, but I will definitely will listen.

Use Selenium? Use XPath Checker.

Just a quick note if you are using Selenium to do your tests, and writing your own, you've probably had to write some XPath expressions. I had to write a particularly hard XPath string and got tired of trying to test my XPath expression in Selenium over and over again.

I did some quick Google searching and discovered a Firefox plug-in named XPath Checker. It works two ways:

It rocks.

Categories

Monthly Archives

Tag Cloud

coldfusion web development flex coldfusion builder appearances squidhead coldfusion builder extensions higher ed flash builder air mobile android adobe apptacular html5 driving technical change running a coldfusion shop adobemax06 movable type flash catalyst flash blackberry adobemax07 adobemax08 hero finicky css adobemax09 holy crap i’m a mobile developer centaur basecamp cfc unfuddle motorola metablog irrational characters ios git evangelism devices code reviews ant wharton subversion security phonegap philly philadelphia multidevice knowledge@wharton jobs browserlab adobemax10 adobe tv unfuddlecfc svnauth.cfc semantic html semantic html responsive web design qnx nlb linux jquery mobile java it github flexorg fireworks edge eclipse dreamweaver apps apple adobemax11