All Articles

Generate a QRCode vCard using Go

Every time I receive a business card, I always check if there is a QR code in it. QR codes are very useful since most mobile phone cameras nowadays can automatically recognise QR codes. Once a QR code which contains vCard data is detected, phones automatically launch “Add Contact” with the details read from the QR code. So all you have to do is just tap “Save” to add the new contact. There is no need to fill in your contacts’ information from the business card. This saves a few seconds of our lives. Who wants filling in data? :)

I’ve always been curious how to create these QR codes which contain vCard data so I searched on how to generate them using Go. So after a few minutes, I’ve come up with a solution using an existing library called go-qrcode. The solution is pretty simple using go-qrcode.

Below is the full source code of the example. Since Go is very straightforward, it just takes a few lines to do it. The example reads data from a vcard.txt file and the vcard data is passed into the qrcode library which generates the qrcode image with the encoded vCard data.

package main

import (

	qrcode ""

func main() {

	file, err := os.Open("vcard.txt")
	if err != nil {
	defer file.Close()

	b, err := ioutil.ReadAll(file)
	if err != nil {

	str := string(b)
	qrFname := "vcard-qr.png"

	err = qrcode.WriteFile(str, qrcode.Medium, 256, qrFname)
	if err != nil {


You can use the ZXing generator to generate the vCard data. Below is sample content of vcard.txt

N:Melvin Vivas
TITLE:Senior Software Engineer
EMAIL:[email protected]

To run the example, you need to first download go-qrcode.

$ go get -u

Then, just do the usual, run main.go

$ cd src/
$ go run main.go

After running the application, this will generate a vcard-qr.png image file in the same directory as your application. screenshot

That’s it! Hope you find the example useful! Source code for this example is in my github repo below: