protected void handleDocument(Document document, PdfWriter writer, Map model) throws DocumentException { java.util.List sampleList = (java.util.List) model.get("list"); Integer scapeNo = (Integer) model.get("scapeNo"); Iterator ir = sampleList.iterator(); try { PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false); int scapeN = scapeNo.intValue(); int i = scapeN; int pageI = i; while (ir.hasNext()) { Sample sample = (Sample) ir.next(); String internalId = sample.getPatient().getIntSampleId(); PdfTemplate template = cb.createTemplate(templateW, templateL); // USING ean8 BARCODE Barcode128 code = new Barcode128(); code.setCodeType(Barcode.CODE128); code.setX(0.75f); // log.debug("the x is " + codeEAN.getX()); code.setBarHeight(barcodeSize); code.setSize(0); // code.setCode(formatBarcode(sampleId)); code.setCode(internalId); Image imageBar = code.createImageWithBarcode(template, null, null); template.beginText(); template.setFontAndSize(bf, fontSize); template.moveText(x, y2); template.showText(internalId); template.endText(); template.addImage(imageBar, imageBar.width(), 0, 0, imageBar.height(), x, y1); int yNo = pageI / columnNo + 1; int xNo = pageI % columnNo; int templateX = marginX + (xNo * templateW); int templateY = totalPageY - marginY - (yNo * templateL); // log.debug("the i is "+i + " the adjustY is " + tempYAdjust + " the templateY is " + // templateY); cb.addTemplate(template, templateX, templateY); i++; pageI++; if ((i % (rowNo * columnNo)) == 0) { pageI = 0; // we go to a new page document.newPage(); } } document.close(); System.out.println("Finished."); } catch (Exception de) { de.printStackTrace(); } }