In Memory Canvas

by vrluckyin India

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<a id="alink" href="" target="_blank">testsafdsfsadf</a>

JavaScript

function resetCanvas(canvas,pName,fName,mName,lName,sName,today,dob,hcpApprovedStatusDB,hcpName,regimen) {
        var maxWidth = 400;
        var lineHeight = 10;
				pName=(pName||null)==null?'':pName;
        fName=(fName||null)==null?'':fName;
        mName=(mName||null)==null?'':mName;
        lName=(lName||null)==null?'':lName;
        sName=(sName||null)==null?'':sName;
        
        var ctx1 = canvas.getContext("2d");
        ctx1.font = "11px Sans-Serif";
        ctx1.fillStyle = "#000000";

        var FullName = pName + (pName == '' ? '' : ' ') + fName + (fName == '' ? '' : ' ') + mName + (mName == '' ? '' : ' ') + lName + (lName == '' ? '' : ' ') + sName;

        var strctx = "Name : " + FullName + "         DOB: " + dob + "       Date: " + today;
        wrapText(ctx1, strctx, 5, 10, maxWidth, lineHeight);
				//TODO? verify this condition
        //if(hcpApprovedStatusDB != 'Y' || hcpApprovedStatusDB != 'N'){
        //}
        var strctx2 = "HCP Name : " + hcpName + "    " + regimen;
        wrapText(ctx1, strctx2, 5, 150, maxWidth, lineHeight);

    }

    function wrapText(context, text, x, y, maxWidth, lineHeight) {
        var words = text.split(' ');
        var line = '';

        for (var n = 0; n < words.length; n++) {
            var testLine = line + words[n] + ' ';
            var metrics = context.measureText(testLine);
            var testWidth = metrics.width;
            if (testWidth > maxWidth && n > 0) {
                context.fillText(line, x, y);
                line = words[n] + ' ';
                y += lineHeight;
            }
            else {
                line = testLine;
            }
        }
        context.fillText(line, x, y);
    }


/* Step:1 Modify  signature with patient data */
var canvas = document.createElement("canvas");
canvas.width=420;
canvas.height=180;
canvas.id="c";
console.log(canvas);
var ctx = canvas.getContext('2d');

/*Step:2 HCP Signature*/
//console.log(signatureCanvas.toDataURL());
var...