Because runqian 4.5 does not have the QR code function by default, it must be implemented using a function.
Prepare the library file:
QR code for Java ver. 0.50 BETA: http://www.swetake.com/qr/java/qr_java.html
Or directly download: http://www.venus.dti.ne.jp /~ SWE/Program/qrcode_java0.50beta10.tar.gz
Compile the QR code function:
Package runqian; import Java. AWT. color; import Java. AWT. graphics2d; import Java. AWT. image. bufferedimage; import Java. io. ioexception; import COM. runqian. report4.usermodel. context; import COM. runqian. report4.model. expression. expression; import COM. runqian. report4.model. expression. function; import COM. runqian. report4.model. expression. variant2; import COM. runqian. base4.util. imageutils; import COM. runqian. base4.u Til. reporterror; import COM. swetake. util. qrcode;/*** QR code qrcode function. ** @ author berry */public class qrcodetest extends function {/** (non-javadoc) ** @ see * COM. runqian. report4.model. expression. node # Calculate (COM. runqian. report4 *. usermodel. context, Boolean) */@ overridepublic object calculate (context arg0, Boolean arg1) {// list of parameters passed by calling this function in the report byte [] Want = NULL; if (this. paramlist. size () = 0) {THR Ow new reporterror ("Empty parameter list of QR code udfs");} // obtain the calculated expression (get the parameter passed to the report) expression param1 = (expression) This. paramlist. get (0); If (param1 = NULL) {Throw new reporterror ("invalid parameter in the QR code UDF");} // operation expression, and get the operation result (object) object result1 = variant2.getvalue (param1.calculate (arg0, arg1), false, arg1); If (result1 = NULL) return NULL; If (result1 instanceof string) {string STR = result1.tostring (); // The version is set to 5 bufferedimage Bi = Createqrcode (STR, 'M', 'B', 5, 4, 4); try {want = imageutils. writepng (BI);} catch (ioexception e) {e. printstacktrace () ;}} return want;}/*** create a qrcode image. ** @ Param data * QR code content * @ Param errorcorrection * error correction rate, including L (7%), m (15%), Q (25%), and H (30% ), the default value is m-level * @ Param encodemode * encoding mode, including a, B, and N. The default value is B * @ Param version *, which is between 1 and 40. The higher the version, the larger the information capacity. The default value is 5 <br/> * Module 5, 37*37. The information capacity is [L-level: 864; m-level: 688; q-level: 496; H level: 368] <br/> * more can refer to: http://www.qrcode.com/en/vertable1.html * @ Param linewidth * width, the larger the width of the image, the default is 4 * @ Param blankwidth * width of the blank area of the image, it should be set to a multiple of the line width or 0 * @ return image */Public bufferedimage createqrcode (string data, char errorcorrection, char encodemode, integer version, integer linewidth, integer blankwidth) {qrcode = new qrcode (); // error correction rate, L, Q, H, M (default) qrcode. setqrcodeerrorcorrect (errorcorrection); // mode, A, N, B (default) qrcode. setqrcodeencodemode (encodemode); // version, 1-40qrcode.setqrcodeversion (5); bufferedimage Bi = NULL; graphics2d G = NULL; try {byte [] d = data. getbytes ("gb18030"); Boolean [] [] B = qrcode. calqrcode (d); int qrcodedatalength = B. length; // graphic width int imagelength = qrcodedatalength * linewidth + blakwidth * 2; Bi = new bufferedimage (image Length, imagelength, bufferedimage. type_int_rgb); G = Bi. creategraphics (); G. setbackground (color. white); G. clearrect (0, 0, imagelength, imagelength); G. setcolor (color. black); For (INT I = 0; I <B. length; I ++) {for (Int J = 0; j <B. length; j ++) {If (B [J] [I]) {G. fillrect (J * linewidth + blankwidth, I * linewidth + blankwidth, linewidth, linewidth) ;}}} catch (exception e) {e. printstacktrace ();} finally {If (G! = NULL) {G. Dispose ();} If (Bi! = NULL) {Bi. Flush () ;}return Bi ;}}
Add function definitions to the configuration file
Designer \ WEB \ WEB-INF \ Classes \ config \ customfunctions. Properties
Web apps \ demo \ WEB-INF \ Classes \ config \ customfunctions. Properties
qrcode=0,runqian.QRCodeTest
Set the template as an image field with the value = qrcode (B1), for example:
Preview effect:
References:
[1] Run the reports cell display QR code. http://www.cnblogs.com/javaReport/archive/2012/04/16/2452149.html
[2] using Java to generate QR code image, parse QR code image. http://blog.csdn.net/zklth/article/details/7191190