Wednesday, 14 September 2011

Using iText to create QRCodes

Recently I have been playing around with iText trying to determine how to stamp a QRCode on to dynamically generated Pdfs.

Its simple to create a QRCode using iTexts built in BarcodeQRCode .class but stamping this on to a PDF is alittle bit unusual and I am unable to find an alternative as it stands.

First you must either create a button in code or place the button on your template which is being stamped, I've called mine barcode_button and I placed this on my template in the correct position and size.

Next you must get hold of your button, create your QRCode and the set the button image to be you QRCode you created, then finally replace the button on the PDF with the new one.
When you finalise the document and close it you will end up with a nice QRCode where the button once sat.

Further examples of creating QRCodes with iText can be found @