How to generate a QR code barcode as a PNG file in Javascript

QR codes are a great way to connect with your customer base as well as transmit data very effectively for a number of different applications, from gift cards and coupons to inventory systems. We are going to be using an API to generate some QR codes in no time at all.

Begin by pasting this script tag into your HTML file. This will import our client.

<script src="https://cdn.cloudmersive.com/jsclient/cloudmersive-barcode-client.js"></script>

With our client set up, it’s time to implement our function, like so:

var CloudmersiveBarcodeapiClient = require('cloudmersive-barcodeapi-client');var defaultClient = CloudmersiveBarcodeapiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveBarcodeapiClient.GenerateBarcodeApi();var value = "value_example"; // String | QR code text to convert into the QR code barcodevar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.generateBarcodeQRCode(value, callback);

Enter your text string and the API will send back our QR code as a PNG. Yup, it’s just that easy. Our API also supports a number of other barcode formats including EAN-13 and UPC-E.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store