Example usage for com.lowagie.text Image getInstance

List of usage examples for com.lowagie.text Image getInstance

Introduction

In this page you can find the example usage for com.lowagie.text Image getInstance.

Prototype

public static Image getInstance(java.awt.Image image, java.awt.Color color)
        throws BadElementException, IOException 

Source Link

Document

Gets an instance of an Image from a java.awt.Image.

Usage

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

private float addImage(PdfPCell cell, String name) {
    try {/*from   w w  w  . ja va  2 s  . co  m*/
        java.awt.Image awtImage = (java.awt.Image) iImages.get(name);
        if (awtImage == null)
            return 0;
        Image img = Image.getInstance(awtImage, Color.WHITE);
        Chunk ck = new Chunk(img, 0, 0);
        if (cell.getPhrase() == null) {
            cell.setPhrase(new Paragraph(ck));
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        } else {
            cell.getPhrase().add(ck);
        }
        return awtImage.getWidth(null);
    } catch (Exception e) {
        return 0;
    }
}

From source file:uk.org.rbc1b.roms.controller.volunteer.VolunteerBadgePdfView.java

License:Open Source License

/**
 * Builds the PDF document of the badge.
 *
 * @param model model// w  w w.j av  a  2  s .  c o  m
 * @param stamper pdf stamper allows us to edit existing pdfs
 * @param request http request
 * @param response http response
 * @throws DocumentException if not formed
 * @throws IOException if unable to read and render data
 */
@Override
protected void mergePdfDocument(Map<String, Object> model, PdfStamper stamper, HttpServletRequest request,
        HttpServletResponse response) throws DocumentException, IOException {

    Volunteer volunteer = (Volunteer) model.get("volunteer");
    PdfContentByte cb = stamper.getOverContent(1);
    String assignment = (String) model.get("assignment");

    // Get image
    BufferedImage bufferedImage = (BufferedImage) model.get("bufferedImage");
    Image img = Image.getInstance(bufferedImage, null);

    addImage(cb, img);
    addBarcode(cb, volunteer.getPersonId());
    addVolunteerName(cb, volunteer.getPerson().formatDisplayName());
    addDepartment(cb, assignment);
    addRBCRegionFooter(cb);
}