BarcodeQRCode extends Barcode2D { @Override public Rectangle placeBarcode(PdfCanvas canvas, Color foreground) { return placeBarcode(canvas, foreground, DEFAULT_MODULE_SIZE); } BarcodeQRCode(String code, Map<EncodeHintType, Object> hints);  BarcodeQRCode(String content);  BarcodeQRCode(); String getCode(); void setCode(String code); Map<EncodeHintType, Object> getHints(); void setHints(Map<EncodeHintType, Object> hints); void regenerate(); @Override Rectangle getBarcodeSize(); Rectangle getBarcodeSize(float moduleSize); @Override Rectangle placeBarcode(PdfCanvas canvas, Color foreground); Rectangle placeBarcode(PdfCanvas canvas, Color foreground, float moduleSide); @Override PdfFormXObject createFormXObject(Color foreground, PdfDocument document); PdfFormXObject createFormXObject(Color foreground, float moduleSize, PdfDocument document); java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background);  }
@Test public void barcode01Test() throws IOException, PdfException, InterruptedException { String filename = "barcodeQRCode01.pdf"; PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument document = new PdfDocument(writer); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); BarcodeQRCode barcode = new BarcodeQRCode("some specific text 239214 hello world"); barcode.placeBarcode(canvas, ColorConstants.GRAY, 12); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }
@Test public void barcode02Test() throws IOException, PdfException, InterruptedException { String filename = "barcodeQRCode02.pdf"; PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument document = new PdfDocument(writer); PdfPage page1 = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page1); Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); BarcodeQRCode barcode1 = new BarcodeQRCode("дима", hints); barcode1.placeBarcode(canvas, ColorConstants.GRAY, 12); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }
@Test public void barcodeVersioningTest() throws IOException, PdfException, InterruptedException{ String filename = "barcodeQRCodeVersioning.pdf"; PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument document = new PdfDocument(writer); for(int i = -9; i<42;i+=10) { PdfPage page1 = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page1); Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.MIN_VERSION_NR, i); BarcodeQRCode barcode1 = new BarcodeQRCode("дима", hints); barcode1.placeBarcode(canvas, ColorConstants.GRAY, 3); } document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }