List of usage examples for com.lowagie.text.pdf Barcode128 setFont
public void setFont(BaseFont font)
From source file:be.fedict.eid.applet.service.impl.PdfGenerator.java
License:Open Source License
/** * Generate a Code128C barcode//from w ww . ja v a 2 s.c o m * * @param rrn unique Rijksregister number * @param cardNumber number of the card * @return Image containing barcode * @throws IOException * @throws BadElementException */ private Image createBarcodeImage(String rrn, String cardNumber) throws IOException, BadElementException { if (null == rrn || rrn.length() != 11 || null == cardNumber || cardNumber.length() < 9) { throw new IllegalArgumentException("Missing or invalid length for RRN or Card Number"); } String lastDigits = cardNumber.substring(cardNumber.length() - 9); String code = rrn + lastDigits; Barcode128 barcode = new Barcode128(); barcode.setCodeType(Barcode128.CODE_C); barcode.setCode(code); barcode.setFont(null); return Image.getInstance(barcode.createAwtImage(Color.BLACK, Color.WHITE), null, true); }
From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java
License:Open Source License
public void addLabelsForSamples(List<TridasSample> samples) { // Loop through samples in list for (TridasSample s : samples) { Barcode128 barcode = new LabBarcode(LabBarcode.Type.SAMPLE, UUID.fromString(s.getIdentifier().getValue().toString())); // if it's tiny, hide the label if (margins.getLabelHeight() * .80f < barcode.getBarHeight()) { barcode.setBarHeight(margins.getLabelHeight() * .45f); barcode.setX(1.8f);//from w w w .j a v a 2s . c o m barcode.setN(10f); barcode.setSize(10f); barcode.setBaseline(10f); barcode.setBarHeight(50f); barcode.setFont(null); } else { barcode.setBarHeight(margins.getLabelHeight() * .45f); barcode.setX(0.6f); barcode.setSize(4.0f); } PdfPCell lbcell = new PdfPCell(); lbcell.setVerticalAlignment(Element.ALIGN_TOP); lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT); Phrase p = new Phrase(); String labelText; TridasGenericField labcodeField = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText"); if (labcodeField == null) { log.warn("labcode missing from sample. Can't print!"); continue; } labelText = (labcodeField != null) ? labcodeField.getValue() : s.getTitle(); p.add(new Chunk(labelText, labelfont)); //p.add(new Chunk("bbb", labelfont)); //p.add(new Chunk(s.getIdentifier().getValue().toString(), uuidfont)); //barcode.setFont(null); Image img = barcode.createImageWithBarcode(contentb, Color.black, Color.gray); PdfPCell labcell = new PdfPCell(); if (App.getLabName() != null) { labcell.setHorizontalAlignment(Element.ALIGN_RIGHT); labcell.setVerticalAlignment(Element.ALIGN_TOP); Phrase labPhrase = new Phrase(App.getLabName().toUpperCase(), tinyfont); labcell.addElement(labPhrase); } addCell(labcell); PdfPCell bccell = new PdfPCell(); bccell.setHorizontalAlignment(Element.ALIGN_MIDDLE); bccell.addElement(img); bccell.addElement(p); addCell(bccell); lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT); lbcell.addElement(p); addCell(lbcell); //addCell(new PdfPCell()); /** PdfPTable tbl = new PdfPTable(2); tbl.addCell(bccell); tbl.addCell(lbcell);*/ } }