Friday, August 20, 2010

Terrence Ryan taught me why <cfhtmlfoot> is not needed

I guess most of you have heard of or used <cfhtmlhead> for injecting things in between <head></head> in html, right?

Today I came across a blog post which talks about frontend performance tips, and one of them is to include script tags in the bottom of the page to avoid blocking (for more tips, see http://code.google.com/speed/articles/ ).  I know this tip for a while now, but I found myself hard to implement it with most MVC frameworks I used (i.e. MG2, ColdBox, FW/1).  For a second I really wish there's a <cfhtmlfoot> tag.  So I asked on the tweeter, and @tpryan replied:

@henrylearn2rock I use the request scope for this. Inject code into request.footer, then in the closing of my view, check for and publish.
Nice!  I guess we don't need <cfhtmlfoot> after all.  Thanks Terrence.

edit: gosh blogger, html encode post title and body ALREADY! And why are URL's not turned into hyperlinks automatically? You suck! It's 2010!!!

update: wow! look at this reply from @mach_ii!

@henrylearn2rock M2 supports this on OpenBD. cfhtmlbody: http://is.gd/esh24 & htmlbody(): http://is.gd/esh0Z Railo tix: http://is.gd/esh7x

update: oh, my man tpryan also blogged about this: Injecting JavaScript to the foot of a ColdFusion Page

Thursday, August 12, 2010

How to render Chinese / Japanese correctly with cfdocument / cfreport?

In order to have the Chinese or Japanese characters rendered up correctly in PDF using and , you should first check what's your default locale at ColdFusion Administrator -> Setting Summary -> Java Default Locale.  One would have thought CFML will respect custom locale using setLocale(), but it doesn't.

If it is "en_US", edit /lib/cffont.properties.  Otherwise, create a /lib/cffont.properties.#locale#(e.g. /lib/cffont.properties.zh_TW )  using cffont.properties as reference.


Replace the font(s) after '=' with system's Chinese font (e.g. MingLiu) for Chinese or system's Japanese font (e.g. MS UI Gothic) for Japanese respectively, assuming ColdFusion is installed on Windows, and client has the respective font(s) installed.

Restart ColdFusion, and then the font should show up correctly...

p.s. In Report Builder, make sure you set Preference -> PDF Encoding to "Identity-H".

Now with the PDF open, Right-click -> Document Properties... , you should see the specified font  in the cffont properties file.

Hmm... now why can't PDF support UTF-8 correctly is beyond me...  How to display both Chinese and Japanese and Korean in the same PDF?  I don't know.

If you know which Chinese / Japanese / Korean fonts are installed by Adobe Reader language pack, please let me know here: http://stackoverflow.com/questions/3474221/which-fonts-are-installed-by-adobe-reader-asian-and-extended-language-font-packs

If you have a better method of getting cfreport / cfdocument render Chinese / Japanese / Korean, please share in Comments!

Thank you

update: if you don't need PDF, format="flashpaper" just works. Thanks Macromedia!