Skip to main content

%SYS.QRCode

abstract class %SYS.QRCode extends %SYSTEM.Help

This class contains methods which will allow you to generate a QR Code, and either store it in a file, or return an image of it. The following QR Code images were created by this class, and then embedded in this web page.



See the Wikipedia article at http://en.wikipedia.org/wiki/QR_code for more information about QR Codes.



See also the Wikipedia article at http://en.wikipedia.org/wiki/URI_scheme for more information about URI QR encoding schemes.


Use of this class requires that Java be installed on your system, and that the Java executable be accessible. The location of the Java executable which is used is determined in the following order:

1) The directory location returned by the configuration parameter JavaHome, located in the [SQL] section of the Cache.CPF file.
2) The directory location returned by the environment variable "JAVA_HOME".
3) Determined by your path variables.

The minimum required Java version to run this package is 1.7.

This method is not supported on VMS platforms and will return an error if called.

This implementation depends on the open source ZXing ("zebra crossing") product. The needed jar files, fop/lib/fop-zxing-0.1.2-jar-with-dependencies.jar and fop/lib/javase-2.0.jar and are distributed in /fop/lib. ZXing uses the same Apache 2.0 license as other jars which are already redistributed with Cache.

Method Inventory

Methods

classmethod GenerateFile(QRString As %String, ByRef Filename As %SysPath = "", Dimension As %Integer = 200, CorrectionLevel As %String = "H") as %Status
Generate a QR Code image in a file.
Given a string, this method will generate a QR Code from the string, and write the image of it to the passed in file name in PNG format.

Parameters:

QRString - String from which to generate the QR Code image from.
Filename - (by ref) File where the image is written.
If filename is passed as a null string, then a temporary file is created with the QR Code image written to it, and the name of the file is returned in Filename. If a Filename is passed in,and the file already exists, an error is returned.
Dimension - (default 200) Size in pixels of how large the image should be. If 100 is passed in, an image 100 x 100 pixels is generated. If the image will not fit in the Dimension specified, then the dimension will be increased to an appropriate size.
CorrectionLevel - (default "H") One of the following levels of correction.
"L" - Low, 7% of codewords can be restored.
"M" - Medium 15% of codewords can be restored.
"Q" - Quartile 25% of codewords can be restored.
"H" - High 30% of codewords can be restored.

Notes:
This method require the %Service_Callout:USE resource to run.


If the QRString contains wide characters, the string is encoded in UTF-8 before the image is generated.

The CorrectionLevel specified determines the maximum length of the QRString which can be encoded. the following is a table of the maximum length for each Correction Level:
L - 4,296
M - 3,391
Q - 2,420
H - 1,852

Examples:

Generate a QR Code image in a file which when read directs your browser to the InterSystems web site.

Set x=##Class(%SYS.QRCode).GenerateFile("http://www.intersystems.com","intersystems.png")



Generate a QRCode Image in a file which when read generates an e-mail to the InterSystems support team:

Set x=##Class(%SYS.QRCode).GenerateFile("mailto:support@intersystems.com?subject=A%20QR%20Code%20Test&body=This%20is%20a%20QR%20Code%20Test.%20%0A","support.png")

classmethod GenerateImage(QRString As %String, ByRef QRImage As %Binary, ByRef QRDataURI As %String, Dimension As %Integer = 800, CorrectionLevel As %String = "H") as %Status
Generate a QR Code image in a binary string.
Given a string, this method will generate a QR Code from the string, and store the binary representation of it in a string.

Parameters:

QRString - String from which to generate the QR Code image from.
QRImage (by ref) - Returned binary representation of the created image in PNG format.
QRDataURI (by ref) - Encoded representation of the created image, suitable to be displayed in an HTML Data URI control.
Dimension - (default 200) Size in pixels of how large the image should be. If 100 is passed in, an image 100 x 100 pixels is generated.
CorrectionLevel - (default "H") One of the following levels of correction.
"L" - Low, 7% of codewords can be restored.
"M" - Medium, 15% of codewords can be restored.
"Q" - Quartile, 25% of codewords can be restored.
"H" - High, 30% of codewords can be restored.

Notes:
This method require the %Service_Callout:USE resource to run.


If the QRString contains wide characters, the string is encoded in UTF-8 before the image is generated.

The CorrectionLevel specified determines the maximum length of the QRString which can be encoded. the following is a table of the maximum length for each Correction Level:
L - 4,296
M - 3,391
Q - 2,420
H - 1,852

The QRDataURI value returned is in the format:

"data:image/gif;base64,"_Base64Encode(QRImage)

It can be displayed as an image in a ZEN page with the following ZEN control:

image id="QRCode" width="200" height="200" src=""

and then setting the src parameter as follows:

s Status=##Class(%SYS.QRCode).GenerateImage(String,,.DataURI)
Set ..%GetComponentById("QRCode").src = DataURI

Inherited Members

Inherited Methods

FeedbackOpens in a new tab