Log in to like this post! Creating a vCard QR Barcode generator with jQuery igQRCodeBarcode control Marina Stoyanova / Thursday, February 27, 2014 The igQRCodeBarcode control is an HTML5, canvas control for Data Visualization. It presents different kind of information like URLs, personal contacts and etc. by rendering a Quick Response (QR) Code. The control supports several options for optimizing the size, readability and the position of the generated code. In the current blog we are going to see how to create a vCard QRBarcode for electronic business cards. vCard is a file format standard for electronic business cards. Those cars can contain various information like name, address, phone numbers and emails as well as logos, photos and URLs. In order to create a vCard you should follow some specifications which we are going to look at further in the blog. Initial steps The minimum requirements needed to configure the igQRCodeBarcode are setting its dimensions – width and height and set a value for the data option. The value for the data should be a string containing the information we wand to encode in the QR code. We will discuss how to create a vCard data later in the blog. The main features of the control can be grouped in three main categories: 1. Look and feel – the functions from this category can be used to customize the barcode by changing the bars; color as well as its background. The second category is the QR-code specific – using the features in this category you can set the error correction level, the size version, encoding mode and other. The third category unites functions that are responsible for configuring the control’s size, stretch and fill. Let’s take a look at some of those functions. We want to add a lot of information in the code that is why we are going to use the barsFillMode property and it is important to set it to ensureEqualSize value to ensure that it will be easily readable by the QR readers. The default value for the property is fillSpace, meaning that the code image will fill the whole space available for the igQRCodeBarcode. Another property that we are going to use is the errorCorrectionLevel . The error correction is a build-in functionality which restores encoded data which has been damaged or dirty. The data recovery level is at the 15% of damaged symbols by default meaning that the errorCorrectionLevel is set to medium. We will set it to low which is equal to 7% of damages symbols that can be restored. Pay attention that the higher the correction level is, the higher the storage capacity will be required from the user’s device for scanning the QR code. The last property I want to mention is the sizeVersion. This feature specifies the the size version of the QR code barcode matrix. The size version refers to the number of the black and white modules that make up the matrix. The control supports size versions from version 1 to version 40. The first version corresponds to 21x21 size module matrix and the version 40 corresponds to 177x177 modules. If you don’t set any version, the control automatically will use the smallest version that fits the data. You can fine detailed information about the igQRCodeBarcode control in the documentation or the API. $("#barcode").igQRCodeBarcode({ height: "200px", width: "200px", barsFillMode: "ensureEqualSize", errorCorrectionLevel: "low", data: "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Somebody\r\nFN:Somebody\r\nORG:Organization's name\r\nTITLE:Job title\r\nTEL;TYPE=cell:555555555\r\nEMAIL;PREF;INTERNET:example@example.com\r\nEND:VCARD" }); To create an electronic business card we will need a form where the users will be able to fill in their information. We are going to use the igTextEditors for that purpose. The igTextEditor control provides a lot of features for styling the input and giving it a unique view. HTML: <form id="businessCardInfo"> <fieldset id="field"> <legend>Personal Informationlegend> <div class="popoverTooltip"> <label>Prefix: label> <br> <input id="textEditor" type="text" name="prefix" title="Mrs, Miss, Dr ..."><br> <label><span class="req">* span>First Name: label> <br> <input id="textEditor1" type="text" name="firstName" title="first name" required><br> <label>Middle Name: label> <br> <input id="textEditor2" type="text" name="middleName" title="middle name"><br> <label><span class="req">* span>Last Name: label> <br> <input id="textEditor3" type="text" name="secondName" title="last name" required><br> <label><span class="req">* span>E-mail: label> <br> <input class="output" id="textEditor4" type="text" name="email" title="example@example.com"><br> <label>Phone(Home): label> <br> <input class="output" id="textEditor5" type="text" name="usrtel" title="555-555-555"><br> <label>Mobile: label> <br> <input class="output" id="textEditor6" type="text" name="mobile" title="555-555-555"><br> <label>Twetter: label> <br> <input class="output" id="textEditor18" type="text" name="twi" title="twitter"><br> div> fieldset> <fieldset id="field2"> <legend>Office Informationlegend> <div class="popoverTooltip"> <label><span class="req">* span>Organization:label><br> <input class="output" id="textEditor7" type="text" name="companyName" title="Company name"><br> <label><span class="req">* span>Job Title :label><br> <input class="output" id="textEditor8" type="text" name="position" title="Job title like: CEO, Software Engineer,..."><br> <label>Business E-mail: label> <br> <input class="output" id="textEditor9" type="text" name="email" title="example@example.com"><br> <label>Business Phone: label> <br> <input class="output" id="textEditor10" type="text" name="usrtel" title="555-555-555"><br> <label>Fax: label> <br> <input class="output" id="textEditor17" type="text" name="usrtel" title="555-555-555"><br> <label>Website: label> <br> <input class="output" id="textEditor11" type="text" name="homepage" title="www.example.com"><br> div> fieldset> <fieldset id="field3"> <legend>Office Addresslegend> <div class="popoverTooltip"> <label>Street: label> <br> <input id="textEditor13" type="text" name="street" title="bul. Simeonovsko Shose 110B"><br> <label>City: label> <br> <input id="textEditor14" type="text" name="city" title="Sofia, New York, London,... "><br> <label>State/Province: label> <br> <input id="textEditor15" type="text" name="state"><br> <label>Country: label> <br> <input id="textEditor12" type="text" name="country" title="UK, USA, Bulgaria, ..."><br> <label>Zip/Postal Code: label> <br> <input id="textEditor16" type="text" name="zipcode"> div> fieldset> <br> <button id="generateBC" value="GenerateBarcode">Generate Barcodebutton> form> JS: $('#textEditor').igTextEditor({ width: 220 }); $('#textEditor1').igTextEditor({ width: 220 }); $('#textEditor2').igTextEditor({ width: 220 }); . . . Image: vCard Specifications The most important thing about the igQRCodeBarcode is the data. To create a vCard we should follow some specifications. A vCard is a collection of one or more properties and a property is a uniquely named value. We should attach our values to those properties if we want our information to be encoded correctly. We are going to look at some of the properties and how to attach our data to them. Every vCard begin with “BEGIN:VCARD” and is followed by the version “VERSION:2.1” and ends with “END:VCARD”. Other properties can be defined in any order you like. The whole list of properties can be found in Wikipedia. We are going to look at some of the properties just to give you a hint how to use them.The “N” value corresponds to the name property which specifies the person, place or thing associated with the vCard. The Formatted name property specifies the way the name is going to be displayed. The unique name for this property is “FN”. Those two properties has fields for the names of the person, thing or place associated with the card as well as fields for suffix and prefix if needed. We take the values from the input using the igTextEditor methods and then concatenate those values to create a valid string. var prefix = $("#textEditor").igTextEditor("text"); var firstName = $("#textEditor1").igTextEditor("text"); var middleName = $("#textEditor2").igTextEditor("text"); var secondName = $("#textEditor3").igTextEditor("text"); if (prefix != "" || prefix != null) { if (middleName != "" || middleName != null) { barcodeN = "N:" + secondName + ";" + middleName + ";" + firstName + ";" + prefix + "\r\n"; barcodeFN = "FN" + prefix + firstName + " " + middleName + " " + secondName + "\r\n"; } else { barcodeN = "N:" + secondName + ";" + firstName + ";" + prefix + "\r\n"; barcodeFN = "FN" + prefix + firstName + " " + secondName + "\r\n"; } } else { if (middleName != "" || middleName != null) { barcodeN = "N:" + secondName + ";" + middleName + ";" + firstName + "\r\n"; barcodeFN = "FN" + firstName + " " + middleName + " " + secondName + "\r\n"; } else { barcodeN = "N:" + secondName + ";" + firstName + "\r\n"; barcodeFN = "FN" + firstName + " " + secondName + "\r\n"; } } For the inputs which contain separate values corresponding to separate vCard properties we overwrite the value method. In those text editors we add an appropriate template. For example for the mobile phone input we will need a template of the following kind:"TEL;CELL;VOICE:{0}\r\n" there the {0} symbol will be replaced by the input text. var originalValue = $.ui.igTextEditor.prototype.value; $.widget("ui.igTextEditor", $.extend({}, $.ui.igTextEditor.prototype, { value: function () { if ((val = originalValue.apply(this, arguments))) { return this.options.outputTemplate.replace("{0}", val); } return val; } })); $('#textEditor4').igTextEditor({ width: 220, outputTemplate: "EMAIL;INTERNET:{0}\r\n" }); $('#textEditor5').igTextEditor({ width: 220, outputTemplate: "TEL;HOME;VOICE:{0}\r\n" }); $('#textEditor6').igTextEditor({ width: 220, outputTemplate: "TEL;CELL;VOICE:{0}\r\n" }); $('#textEditor7').igTextEditor({ width: 220, outputTemplate: "ORG:{0}\r\n" }); $('#textEditor8').igTextEditor({ width: 220, outputTemplate: "TITLE:{0}\r\n" }); $('#textEditor9').igTextEditor({ width: 220, outputTemplate: "EMAIL;PREF;INTERNET:{0}\r\n" }); $('#textEditor10').igTextEditor({ width: 220, outputTemplate: "TEL;WORK;VOICE:{0}\r\n" }); $('#textEditor11').igTextEditor({ width: 220, outputTemplate: "URL:{0}\r\n" }); Summary Creating an electronic business card as a barcode is a modern and handy way to add new contacts to your phone or just receive information about somebody. The vCards contain various information starting from personal data as name, phone and email and continuing with information about business such as office address, job title, office name and business phone and emails. Adding all that information in a QR code makes its readability harder, but the igQRCodeBarcode supports several options for optimizing the size, readability and the position of the generated code. See a live demo of the QRCodeBarcode generator on jsFiddle or download the sample. You can follow us on Twitter @Infragistics and stay in touch on Facebook, Google+ and LinkedIn!