Friday, 28 February 2014

ColdFusion 11: <cfhtmltopdf> is pretty good!

G'day:
I had a bit of a false start with getting cfhtmltopdf() working (see article "ColdFusion 11: cfhtmltopdf() a non-starter. Literally"), but that turned out to be an installer problem, rather than anything wrong with the functionality itself. Once I got it going, I gotta say I'm pretty impressed.

I simply knocked together this code, and ran it with some common websites to see what the output was like:

param URL.htmlUrl;

pdfDir = expandPath("./pdfs/");
pageName = listLast(URL.htmlUrl, "/");
pdfPath = pdfDir & pageName & ".pdf";
try {
    startTime = getTickCount();
    cfhtmltopdf(source=URL.htmlUrl, destination=pdfPath, overwrite=true);
    totalTime =getTickCount() - startTime;
    writeOutput("Execution time: #totalTime#ms<br>");
}catch (any e){
    writeDump(e);
}

The table below details the sites I used, and links through to the generated PDFs (and, for reasons best known to myself, a thumbnail of the generated PDF: I just wanted to mess with <cfpdf>, basically).

SitePDF
This blog
BBC News
The Guardian
Pravda
Al Jazeera
Asahi
Xin Hua

If you can't be arsed looking at the sites, the bottom line is this: the English-language sites all rendered really well. Not perfectly, but definitely good enough to be used in a professional capacity, I think. The Russian-language site (Pravda) and Japanese (Asahi) also generated fine.

However Chines (Xin Hua) and Arabic (Al Jazeera) sites both generated the structure OK, but the text was lost. This is a bit of a mishit, and should have been spotted by Adobe I think. We live in an increasingly small and polylingual world, and not dealing with - especially - Chinese is poor form.

I also had a concern about generation times. Here's how long each PDF took to generate:

SiteDuration
blog40sec
BBC22sec
Guardian52sec
Pravda37sec
Al Jazeera55sec
Asahi91sec
Xinhua168sec

I'm not concerned about the times themselves; although 3min to generate a PDF does seem like a long time... especially as we can only write off about 10sec of that for load time... I'm concerned about the fact that two of those are higher than my request timeout period. It seems that the request timeout doesn't apply to this process? That's not great. I know that the way ColdFusion handles request timeouts is such that some processes seem immune to it. This doesn't make it correct to behave that way. If I specify a request time out, that should be the timeout for a request. Fullstop. It should not be a timeout "in most situations, but not if you use these tags". That's dumb. I think Adobe need to revisit how this is handled.

Anyhow, I did not exactly push the envelope as far as this functionality goes... I'm not meaning to test the entire thing, attribute by attribute, I just wanted to see how good the PDFs were.

Whilst the PDFs were good, there are two things about this functionality which are very subpar:

  1. It's enterprise only. Come on Adobe, give us a break. It's bad enough we've gotta pay for CFML without having to pay an Enterprise price ticket to even get the functionality. Enterprise should be about scale, not about hamstringing. You need to provide this functionality to all CF licences, and perhaps throttle it in some way. But not in a way that makes it unusable.
  2. It's... I don't believe I need to say this in regards to any web technology... it's Windows-only. Seriously: f*** the hell right off with that (and I say this as someone who only uses Windows!). What were you thinking? Windows only? In a web environment? You guys are hung-up in the desktop market most of Adobe's functionality is based around. Plus you can't - in the same breath - go "Enterprise-only" and then go on to say "Windows-only". Are you on particularly impure crack?

Bottom line: Adobe need to sort out Chinese and Arabic (and any other significant language(s) it's missed support for), and maybe look at how long the rendering takes. But overall I think this functionality is good. However they seriously need a kick up the arse for the Enterprise-only and Windows-only thing. That's just stupid. Stupid and out of touch with reality.

Righto.

--
Adam