Skip to Content
Dear all,
             In this blog I’ll give you an explanation about how to  generate QR Code(Qick Response code)image by passing the static variables and how to download the QR Code & its variables in PDF format.

             First we need to create Project in SAP Web IDE,here iam creating a project with the name of “QRCodegenerator” which is shown below the Workspace.

             After creating the project we will get view(QRCode.view.xml)and controller(QRCode.controller.js).

       In my XML view I have placed image tag for image and Button for downloading image, placed with in the content shown in below.

  <Page title="{i18n>title}">
	       <Image class="qrCodfe" id="qrImageId"/>
	       <Button press="onButtonPress" text="Pdf Download" type="Emphasized" class="pdfButton"/>



How to set the Qr Code Image to the View.

         Now Generated QR Code image  is displayed in view, for that here iam getting the image ID from the view(QRCode.view.xml) and set the QR Code url to the view,that was show in below.

		onInit: function() {
			var SCAC = "A1";
			var TRAILER = "11";
			var SHIPMENT = "12";
			var SHIPPER = "abc1";
			var SHIPTO = "abc2";
			var ORDDATE = "20-01-2018";
			var BOL = "Bold";
			var PRODBATCH = "value";
			var SHIPQTY = "10";
			qrurl = '' + SCAC + '/TRAILER:' + TRAILER + '/SHIPMENT:' +
				'/SHIPQTY:' + SHIPQTY + '';



Now run you are app to get the output like this (Generated QR Code displayed in view):

                  Now we click on the Pdf Download button to get the QR Code with variables(here my function name is “onButtonPress”).
How to convert the QR Code url in to base64_data Format: 

                  Before downloading the QR Code, It is necessary to convert the QRCode url(Image) into the base64 format other wise you can't download the QRCode Image. that was show in below.

onButtonPress: function() {
            var Spliturl = qrurl;
	    var split = Spliturl.slice(0, 169);
	    var Parameters = Spliturl.split("chl=");
	    var values = Parameters[1];
	    var Fianlvalues = values.split("/");

/* ------- URL converstion to base64_data ------*/
            var convertImgToDataURLviaCanvas = function(url, callback) {
	          var img = new Image();
	               img.crossOrigin = 'Anonymous';
	               img.onload = function() {
            var canvas = document.createElement('CANVAS');
		  var ctx = canvas.getContext('2d');
		  var dataURL;
		  canvas.height = this.height;
		  canvas.width = this.width;
		  ctx.drawImage(this, 0, 0);
		  dataURL = canvas.toDataURL();
		  canvas = null;
		img.src = url;

convertImgToDataURLviaCanvas(split, function(base64_data) {
		var sometext1 = "QRCode and it's Veriables";
		var sometext = Fianlvalues;
		var pdf = new jsPDF();

		pdf.addImage(base64_data, 'JPEG', 2, 90, 70, 70);
		pdf.text(70, 10, sometext1);
		pdf.text(5, 30, sometext);'Test.pdf');

                 When ever you can use the jsPDF function in our controller, you can must add the “jspdf.min.js” script tag in your index.html file. 

Now go to your index.html file and add the following code:
     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta charset="UTF-8">


		<script id="sap-ui-bootstrap"
			data-sap-ui-resourceroots='{"QRCodegenerator": ""}'>

<link rel="stylesheet" type="text/css" href="css/style.css">

			sap.ui.getCore().attachInit(function() {
				new sap.m.Shell({
					app: new sap.ui.core.ComponentContainer({
						height : "100%",
						name : "QRCodegenerator"
				<script src=""></script>


After adding the Script tag in index.html page, now we click on the  download button to get the pdf form show in below(Test.pdf):

Finally we have to open the pdf file for getting  the QR Code image and veriables like this: 






To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply