Tuesday, June 30, 2009

Solution to CFIMAGE distorting text.

CFIMAGE, CFPDF and CFDOCUMENT all rely on the Fonts installed on the server where Coldfusion is installed.

You may find as I did that these tags sometimes render fonts strangly. In my case it was CFIMAGE that was drawing out strange characters for letters. I googled the issue and found NO good answer. Adobe's forums didn't help either.

So here is the solution! For FREE!

The CFIMAGE tag contains an attribute called "fonts". To stop having CF pull random fonts, you must open up your CFADMIN console (if you have access to it) and look in the Font Management section or TRUE TYPE fonts.

On my server I have several fonts listes but only few are TRUE TYPE.

ONLY True type will work (in my experience).

Copy and paste one of the font names in the CFADMIN into the "fonts" attribute. This will restrict CFIMAGE to just that font. If you want more than one font type to display, you can list out the fonts in comma delimited format.

So here's an example:

<cfimage overwrite="Yes"
action = "captcha"
height = "60"
text = "rEadMe"
width = "200"
fonts = "lucida sans,lucida sans typewriter"
fontsize = "30"
destination = "assets/images/captcha.jpg"
difficulty = "medium">

That's it! Good luck!

Thursday, February 26, 2009

Get your GMAIL using Coldfusion's CFPOP

Here is a code sample on how to pull your email off of Gmail.

<cfset javaSystem = createObject("java", "java.lang.System") />
<cfset jProps = javaSystem.getProperties() />
<cfset jProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
<cfset jProps.setproperty("mail.pop3.port",995) />
<cfset jProps.setProperty("mail.pop3.socketFactory.port", 995) />

<cfpop action="GETALL" name="getMail" server="pop.gmail.com" username="[yourUserName]" password="[yourPassword]" port="995" maxrows="20" timeout="90">

<cfdump var="#getMail#">

Be sure to enable POP on your gmail account


Fusecast Web Application Development and Web Hosting Services
www.fusecast.com

Monday, February 23, 2009

I.E. Select Drop Down Cuts Off Using CSS width

The Problem
While setting up an HTML form I ran into an issue where the select box I was using has an option that was really really long. I set the size of the select box to 166px using CSS styles. Except for I.E., Firefox and every other real browser out there handled it just fine. Since the bulk of my users use I.E., I needed to come up with a hack that would not add a lot of code overhead and be maintainable.

Here's what I came up with and it works great!

The Solution

Original Code
<form name="test">
<select name="safetyProgram" id="safetyProgram" style="width:166px;">
<option value="0" selected>No safety program</option>
<option value="1">Cost containment safety program as certified by the state</option>
<option value="2">Formal written safety program with management oversight including inspections, written documentation, on regular meetings</option>
<option value="3">Formal written safety program with regular meeting</option>
<option value="4">Any safety program less than the aformentioned categories</option>
</select>
</form>

Sample




New Code
<form name="test">
<select name="safetyProgram" id="safetyProgram" style="width:166px;position:absolute;z-index:50;" onfocus="this.style.width='auto';" onblur="this.style.width='166px';">
<option value="0" selected>No safety program</option>
<option value="1">Cost containment safety program as certified by the state</option>
<option value="2">Formal written safety program with management oversight including inspections, written documentation, on regular meetings</option>
<option value="3">Formal written safety program with regular meeting</option>
<option value="4">Any safety program less than the aformentioned categories</option>
</select>
</form>


Sample



Note: If you want to constrict the size the drop down option opens out to, simply change the width parameter in the onFocus from auto to say 300px or something. Play with it. You'll get the idea.

And YES, this hack makes the select box float over your other form widgets and text so it doesn't do strange things with the other form elements.

Have a go at it! It did the trick for me. I hope it works for you too!

Tuesday, January 27, 2009

Binary Object Decoding, Transmitting, Encoding Using Coldfusion

As we start delving into storing binary objects (pdf's, images etc) this post will help you encode, decode and/or transmit the data you are working with. Now I am coming from the perspective of a CF developer so you will need to adapt where need be for environment.

We start with a Binary Object (an image).

1. Binary Object
2. Convert it to base64 for transmitting via xml or another HTTP method
---> a. CF method: toBase64(binaryObj)
3. Receiver takes the data and encodes it back to a binary object
---> a. CF method: toBinary(base64String)

Example:


<cfquery name="q" datasource="#REQUEST.mysqldsn#">
SELECT binaryColumn <!--- This column is a longblob --->
FROM mytable
</cfquery>

<!--- View the data from the DB call --->
<cfdump var="#q#">

<!--- Create a way to view the binary object --->
<cfset myImg1 = ImageNew(q.document)>
<cfimage action="WRITETOBROWSER" source="#myImg1#">

<!--- Now convert the binary object from the DB to a base64 string --->
<cfset doc = tobase64(q.document)>
<!--- Display the base64 string --->
<cfoutput>#doc#</cfoutput>

<!--- Convert the base64 string to a binary object --->
<cfset doc = toBinary(doc)>

<!--- Dump the converted base64 to a binary object to view it --->
<cfdump var="#doc#">

<!--- Create a way to view the binary object --->
<cfset myImg2 = ImageNew(doc)>
<cfimage action="WRITETOBROWSER" source="#myImg2#">

Note: Be sure you change your CFADMIN longblob size limits if you need to store large binary objects. Otherwise the data will be truncated.