4.11.2013

QR Code dynamic URL working example using ColdFusion

Follows a simplified for better understanding Coldfusion webpage, a working example of how the trick is done:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<cfchart name="myChart"
       format="png"
       scalefrom="0"
       scaleto="10"
       yaxistitle="Number of students"
       xaxistitle="Grade" chartwidth="620"
       chartheight="375"
       showlegend="true"
       databackgroundcolor="##C9DEFA"
       seriesplacement="default">
     
      <cfchartseries
          type="bar"  markerstyle="circle"
          serieslabel="Female"
          seriescolor="##FFC0FF">
        <cfchartdata item="A" value="121">
        <cfchartdata item="B" value="200">           
        <cfchartdata item="C" value="485">
        <cfchartdata item="D" value="60">
        <cfchartdata item="E" value="20">
        <cfchartdata item="F" value="15">
        <cfchartdata item="Absent" value="2">
        <cfchartdata item="Need assistency" value="9">
      </cfchartseries>

      <cfchartseries
          type="bar"  markerstyle="circle"
          serieslabel="Male"
          seriescolor="##3333FF">
        <cfchartdata item="A" value="321">
        <cfchartdata item="B" value="123">           
        <cfchartdata item="C" value="345">
        <cfchartdata item="D" value="43">
        <cfchartdata item="E" value="50">
        <cfchartdata item="F" value="20">
        <cfchartdata item="Absent" value="5">
        <cfchartdata item="Need assistency" value="2">
      </cfchartseries>
</cfchart>

<cfset myFile="#GetDirectoryFromPath(GetBaseTemplatePath())#">

<cfset myFile=myFile.concat("myChart.png")>

<cffile action="WRITE" file="#myFile#" output="#myChart#">

    <cfdocument format="pdf" filename="#GetDirectoryFromPath(GetBaseTemplatePath())#report.pdf" overwrite="true" name="fileContent">

    <center>
    <h2>Schoolar Performance by sex</h2>
   
    <img src="myChart.png">
   
    </center>
    </cfdocument>

<cfloop condition="#FileExists('#GetDirectoryFromPath(GetBaseTemplatePath())#report.pdf')# eq false">     
</cfloop>

<cflocation url="report.pdf">

</body>
</html>
</body>
</html>


Although there´s no query feeding the chart, it could. But for speeding up the availability of this post I decided to publish as it is.

The concept is really, really simple. You grab data from a database. Put it inside a PDF, waits for the PDF to be available on disk and then redirects the browser to it.

This web page will be resting in your web site ready to be triggered. Another step of the process is to get the URL address and make a QR Code from it. Then you publish the QR Code image somewhere.

When someone points a cell phone camera to it, it will deliver to the person consolidated data, always updated, because it is being generated dynamically.

Hope to have improved people´s lives with this.

Comments are very welcome!



No comments:

Post a Comment