List of usage examples for com.itextpdf.text.pdf.qrcode EncodeHintType ERROR_CORRECTION
EncodeHintType ERROR_CORRECTION
To view the source code for com.itextpdf.text.pdf.qrcode EncodeHintType ERROR_CORRECTION.
Click Source Link
From source file:se.billes.pdf.renderer.model.QRCode.java
License:Open Source License
@SuppressWarnings("unchecked") public void onRender(PdfContentByte cb) throws PdfRenderException { float[] positions = new BlockFactory().getBoundsInPs(this); try {/*from w ww . j a v a 2 s . c o m*/ @SuppressWarnings("rawtypes") Hashtable hintMap = new Hashtable(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); PdfDocument req = getPage().getPdfDocument(); QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix byteMatrix = qrCodeWriter.encode(getText(), BarcodeFormat.QR_CODE, (int) (positions[2]), (int) (positions[3]), hintMap); int matrixWidth = byteMatrix.getWidth(); int matrixHeight = byteMatrix.getHeight(); float pageHeight = req.getSize()[1]; float top = getPosition()[1]; if (getPage().getPdfDocument().getCutmarks() != null) { pageHeight += SizeFactory.CUT_MARK * 2; top += SizeFactory.CUT_MARK; } cb.setColorFill(getBaseColor()); float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight); float topInPs = SizeFactory.millimetersToPostscriptPoints(top); for (int i = byteMatrix.getTopLeftOnBit()[0]; i < matrixWidth; i++) { for (int j = byteMatrix.getTopLeftOnBit()[0]; j < matrixHeight; j++) { if (byteMatrix.get(i, j)) { cb.rectangle(positions[0] + (i - byteMatrix.getTopLeftOnBit()[0]), pageHeightInPs - ((topInPs + 1) + (j - byteMatrix.getTopLeftOnBit()[0])), 1, 1); } } } cb.fill(); cb.setColorFill(new ColorFactory().getBlack()); } catch (Exception e) { } }