Skip to content
 
 

Repository files navigation

This plugin allows you to create QR codes as part of your Grails application without the need for an external service.

QrcodeController

Render text QRCode at default size (300x300px)

.../qrcode/text/Hello+World

Render text QRCode in 30x30px

.../qrcode/text?w=30&text=test

QRCode

Render url QRCode

.../qrcode/url?u=http://grails.org/plugin/qrcode

QrCodeService

qrCodeService.renderPng("test", 30, outputStream)

Tag Library

Namespace: qrcode

Render text as QRCode

<qrcode:image height="100" width="100" text="TEST TEXT"/>

If you want to include a QRCode image in an email and you use a GSP to render email content you must set attribute absolute="true". Otherwise the image url will not start with http:// and will probably not render correct.

<qrcode:image height="100" width="100" text="#648357" alt="Invoice #648357" absolute="true"/>

Render current request url as QRCode

<qrcode:url width="64"/>

Render vCard contact information as QRCode

In this example we have a method on the Person domain class that returns contact information as a vCard formatted String.

class Person {
    ...
    transient String getVcard() {
        def s = new StringBuilder()
        s << "BEGIN:VCARD\n"
        s << "VERSION:3.0\n"
        s << "N:${lastName};${firstName};;;\n"
        s << "FN: ${fullName}\n"
        s << "ORG:${companyName}\n"
        s << "TITLE:${title ? title.replace(',', '\\,') : ''}\n"
        s << "TEL;TYPE=work,voice,pref:${phone}\n"
        s << "TEL;TYPE=cell,voice:${cellphone}\n"
        s << "EMAIL;type=internet,pref:${email}\n"
        s << "ADR;TYPE=work,postal,pref:;;${address};${city};${state};${postalCode};${country}\n"
        def timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
        s << "REV:${timestampFormat.format(lastUpdated ?: dateCreated)}\n"
        s << "END:VCARD\n"
        return s.toString()
    }
}

Now it's easy to render a QRCode of the contact information. This QRCode can be scanned with a smartphone and imported as a contact.

<qrcode:image height="150" text="${person.vcard}" alt="${person.fullName} ${person.address} ${person.city}"/>

About

The Grails QR Code plugin

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages