public TicketLabel(Ticket t) { BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); Color c = new Color((float) Math.random(), (float) Math.random(), (float) Math.random()); g.setColor(c); g.fillRect(0, 0, WIDTH, HEIGHT); this.setIcon(new ImageIcon(image)); g.setColor(Color.WHITE); g.fillRect(0, 0, WIDTH, HEIGHT); g.setColor(Color.BLACK); String sid = "" + t.getID(); while (sid.length() < 10) sid = "0" + sid; Barcode b = null; try { b = new Int2of5Barcode(sid); b.draw((Graphics2D) g, 5, 20); } catch (BarcodeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (OutputException e) { // TODO Auto-generated catch block e.printStackTrace(); } g.drawString(t.getCategory().getName(), 5, 12); g.setColor(Color.black); g.drawRect(0, 0, WIDTH, HEIGHT); }
public ByteArrayOutputStream getFilledPdf(Person person, StudentCandidacy candidacy) throws IOException, DocumentException { InputStream istream = getClass().getResourceAsStream(SANTANDER_APPLICATION_CARD_PDF_PATH); PdfReader reader = new PdfReader(istream); reader.getAcroForm().remove(PdfName.SIGFLAGS); ByteArrayOutputStream output = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, output); form = stamper.getAcroFields(); setField("StudentIdentification", person.getIstUsername()); setField("Phone", person.getDefaultMobilePhoneNumber()); setField("Email", getMail(person)); setField( "CurrentDate", new DateTime().toString(DateTimeFormat.forPattern("dd/MM/yyyy HH:mm"))); SantanderPhotoEntry photoEntryForPerson = SantanderPhotoEntry.getOrCreatePhotoEntryForPerson( candidacy.getRegistration().getPerson()); if (photoEntryForPerson != null) { setField("Sequence", photoEntryForPerson.getPhotoIdentifier()); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BarcodeImageHandler.writeJPEG( BarcodeFactory.createCode39(photoEntryForPerson.getPhotoIdentifier(), false), baos); Jpeg sequenceBarcodeImg = new Jpeg(baos.toByteArray()); float[] sequenceFieldPositions = form.getFieldPositions( "SequenceBarcode"); // 1-lowerleftX, 2-lly, 3-upperRightX, 4-ury sequenceBarcodeImg.setAbsolutePosition( sequenceFieldPositions[1], sequenceFieldPositions[2]); sequenceBarcodeImg.scalePercent(45); stamper.getOverContent(1).addImage(sequenceBarcodeImg); } catch (OutputException e) { logger.error(e.getMessage(), e); } catch (BarcodeException be) { logger.error(be.getMessage(), be); } Jpeg photo = new Jpeg(photoEntryForPerson.getPhotoAsByteArray()); float[] photoFieldPositions = form.getFieldPositions("Photo"); // 1-lowerleftX, 2-lly, 3-upperRightX, 4-ury photo.setAbsolutePosition(photoFieldPositions[1], photoFieldPositions[2]); photo.scalePercent(95); stamper.getOverContent(1).addImage(photo); } try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BarcodeImageHandler.writeJPEG(BarcodeFactory.createCode128(person.getIstUsername()), baos); Jpeg studentIdBarcodeImg = new Jpeg(baos.toByteArray()); float[] studentIdFieldPositions = form.getFieldPositions( "StudentIdentificationBarcode"); // 1-lowerleftX, 2-lly, 3-upperRightX, 4-ury studentIdBarcodeImg.setAbsolutePosition( studentIdFieldPositions[1], studentIdFieldPositions[2]); studentIdBarcodeImg.scalePercent(45); stamper.getOverContent(1).addImage(studentIdBarcodeImg); } catch (OutputException e) { logger.error(e.getMessage(), e); } catch (BarcodeException be) { logger.error(be.getMessage(), be); } stamper.setFormFlattening(true); stamper.close(); return output; }