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(Image image) 

Source Link

Document

gets an instance of an Image

Usage

From source file:com.geek.tutorial.itext.image.EmbedImage.java

License:Open Source License

public EmbedImage() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("EmbedImage.pdf"));
    document.open();//from   ww  w.j  a  v  a  2 s . co  m

    // Code 1
    document.add(new Phrase("Please press "));
    document.add(new Chunk(Image.getInstance("save.gif"), 0, 0));
    document.add(new Phrase(" to save the file."));

    document.close();
}

From source file:com.geek.tutorial.itext.image.Transformation.java

License:Open Source License

public Transformation() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("transformation.pdf"));
    document.open();// w w  w  . j a v  a  2 s  . c  om

    Image img = Image.getInstance("square.jpg");
    img.setAbsolutePosition(100, 650); // Code 1

    img.scaleAbsolute(100, 100); // Code 2

    img.setRotationDegrees(40); // Code 3

    document.add(img);
    document.close();

}

From source file:com.google.api.ads.adwords.awreporting.util.MediaReplacedElementFactory.java

License:Open Source License

/**
 * @see org.xhtmlrenderer.extend.ReplacedElementFactory
 *      #createReplacedElement(org.xhtmlrenderer.layout.LayoutContext,
 *      org.xhtmlrenderer.render.BlockBox, org.xhtmlrenderer.extend.UserAgentCallback, int, int)
 *//*from   ww w  . j a v  a2 s .  c  o  m*/
@Override
public ReplacedElement createReplacedElement(LayoutContext layoutContext, BlockBox blockBox,
        UserAgentCallback userAgentCallback, int cssWidth, int cssHeight) {
    Element element = blockBox.getElement();
    if (element == null) {
        return null;
    }
    String nodeName = element.getNodeName();
    String className = element.getAttribute("class");

    // Replace any <div class="media" data-src="image.png" /> with the
    // binary data of `image.png` into the PDF.
    if ("div".equals(nodeName) && className.startsWith("media")) {
        if (!element.hasAttribute("data-src")) {
            throw new RuntimeException("An element with class `media` is missing a `data-src` "
                    + "attribute indicating the media file.");
        }

        InputStream input = null;
        String dataSrc = element.getAttribute("data-src");
        try {

            if (dataSrc.startsWith("http")) {
                input = new URL(dataSrc).openStream();
            } else if (dataSrc.startsWith("data:image") && dataSrc.contains("base64")) {

                byte[] image = Base64.decode(dataSrc.split(",")[1]);
                input = new ByteArrayInputStream(image);

            } else {
                input = new FileInputStream(dataSrc);
            }

            final byte[] bytes = IOUtils.toByteArray(input);
            final Image image = Image.getInstance(bytes);
            final FSImage fsImage = new ITextFSImage(image);
            if (fsImage != null) {
                if ((cssWidth != -1) || (cssHeight != -1)) {
                    fsImage.scale(cssWidth, cssHeight);
                }
                return new ITextImageElement(fsImage);
            }
        } catch (Exception e) {
            throw new RuntimeException("There was a problem trying to read a template embedded graphic.", e);
        } finally {
            IOUtils.closeQuietly(input);
        }
    }
    return this.superFactory.createReplacedElement(layoutContext, blockBox, userAgentCallback, cssWidth,
            cssHeight);
}

From source file:com.googlecode.openmpis.action.AbductorAction.java

License:Open Source License

/**
 * Prints the abductor's poster in PDF file.
 *
 * @param mapping       the ActionMapping used to select this instance
 * @param form          the optional ActionForm bean for this request
 * @param request       the HTTP Request we are processing
 * @param response      the HTTP Response we are processing
 * @return              the forwarding instance
 * @throws java.lang.Exception/*from  w  ww. j av a  2 s  .  c  o  m*/
 */
public ActionForward printPoster(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // Set the paper size and margins
    Document document = new Document(PageSize.LETTER, 50, 50, 50, 50);

    // Create the PDF writer
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    // Retrieve the abductor
    try {
        int id = Integer.parseInt(request.getParameter("id"));

        Abductor abductor = abductorService.getAbductorById(id);

        // Process the photo
        String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + "photo"
                + File.separator + "unknown.png";
        if (abductor.getPhoto() != null) {
            String tokens[] = abductor.getPhoto().split("\\/");
            String defaultPhotoBasename = "";
            for (int i = 0; i < tokens.length - 1; i++) {
                defaultPhotoBasename += tokens[i] + File.separator;
            }
            defaultPhotoBasename += tokens[tokens.length - 1];
            absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/")
                    + defaultPhotoBasename;
        }

        // Add some meta information to the document
        document.addTitle("Poster");
        document.addAuthor("OpenMPIS");
        document.addSubject("Poster for " + abductor.getNickname());
        document.addKeywords("OpenMPIS, missing, found, unidentified");
        document.addProducer();
        document.addCreationDate();
        document.addCreator("OpenMPIS version " + Constants.VERSION);

        // Open the document for writing
        document.open();
        // Add the banner
        Paragraph wantedParagraph = new Paragraph("W A N T E D",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0)));
        wantedParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(wantedParagraph);
        // Add name
        Paragraph redParagraph;
        if (!abductor.getNickname().isEmpty()) {
            redParagraph = new Paragraph(
                    abductor.getFirstName() + " \"" + abductor.getNickname() + "\" " + abductor.getLastName(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
        } else {
            redParagraph = new Paragraph(abductor.getFirstName() + " " + abductor.getLastName(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
        }
        redParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(redParagraph);
        // Add the photo
        Image image = Image.getInstance(absoluteDefaultPhotoFilename);
        image.scaleAbsolute(200, 300);
        image.setAlignment(Image.ALIGN_CENTER);
        document.add(image);
        // Add birth date
        Paragraph blackParagraph;
        if (abductor.getBirthMonth() > 0) {
            blackParagraph = new Paragraph(
                    getResources(request).getMessage("label.date.birth") + ": "
                            + getResources(request).getMessage("month." + abductor.getBirthMonth()) + " "
                            + abductor.getBirthDay() + ", " + abductor.getBirthYear(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
            blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(blackParagraph);
        }
        // Add birth place
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.address.city") + ": " + abductor.getCity(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add sex
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.sex") + ": "
                        + getResources(request).getMessage("sex." + abductor.getSex()),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add height
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.height") + ": " + abductor.getFeet() + "' "
                        + abductor.getInches() + "\"",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add weight
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.weight") + ": " + abductor.getWeight() + " "
                        + getResources(request).getMessage("label.weight.lbs"),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add hair color
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.color.hair") + ": "
                        + getResources(request).getMessage("color.hair." + abductor.getHairColor()),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add eye color
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.color.eye") + ": "
                        + getResources(request).getMessage("color.eye." + abductor.getEyeColor()),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add race
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.race") + ": "
                        + getResources(request).getMessage("race." + abductor.getRace()),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add circumstance
        blackParagraph = new Paragraph(
                getResources(request).getMessage("label.remarks") + ": " + abductor.getRemarks(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add line
        blackParagraph = new Paragraph("---------------------------------------");
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add contact
        blackParagraph = new Paragraph(getResources(request).getMessage("global.contact"),
                FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        document.close();

        // Set the response to return the poster (PDF file)
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        response.setHeader("Content-disposition", "attachment; filename=Poster.pdf");

        // Close the output stream
        baos.writeTo(response.getOutputStream());
        response.getOutputStream().flush();

        return null;
    } catch (NumberFormatException nfe) {
        return mapping.findForward(Constants.LIST_PERSON);
    } catch (NullPointerException npe) {
        return mapping.findForward(Constants.LIST_PERSON);
    }
}

From source file:com.googlecode.openmpis.action.CaseAction.java

License:Open Source License

/**
 * Writes the cases to a PDF file.//from  ww  w. j a va2  s . c om
 *
 * @param mapping       the ActionMapping used to select this instance
 * @param form          the optional ActionForm bean for this request
 * @param request       the HTTP Request we are processing
 * @param response      the HTTP Response we are processing
 * @return              the forwarding instance
 * @throws java.lang.Exception
 */
public ActionForward printCases(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    User currentUser = null;

    // Check if there exists a session
    if (request.getSession().getAttribute("currentuser") != null) {
        currentUser = (User) request.getSession().getAttribute("currentuser");
    }

    // Set the paper size and margins
    Document document = new Document(PageSize.LETTER.rotate(), 50, 50, 50, 50);

    // Create the PDF writer
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    // Add some meta information to the document
    document.addTitle("Case Statistics");
    document.addAuthor("OpenMPIS");
    document.addSubject("Statistics for All Cases");
    document.addKeywords("OpenMPIS, missing, found, unidentified");
    document.addProducer();
    document.addCreationDate();
    document.addCreator("OpenMPIS version " + Constants.VERSION);

    // Set the header
    String date = simpleDateFormat.format(System.currentTimeMillis());
    document.setHeader(new HeaderFooter(new Phrase("Statistics for cases as of " + date), false));

    // Set the footer
    HeaderFooter footer = new HeaderFooter(new Phrase("Page : "), true);
    footer.setAlignment(Element.ALIGN_CENTER);
    document.setFooter(footer);

    // Open the document for writing
    document.open();
    Table table = new Table(2);
    table.setBorderWidth(1);
    table.setBorderColor(new Color(0, 0, 0));
    table.setPadding(2);
    table.setSpacing(0);
    Paragraph paragraph = new Paragraph("Cases",
            FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD, new Color(0, 0, 0)));
    paragraph.setAlignment(Paragraph.ALIGN_CENTER);
    Cell cell = new Cell(paragraph);
    cell.setHeader(true);
    cell.setColspan(2);
    table.addCell(cell);
    table.endHeaders();
    table.addCell("Total On-going Cases");
    table.addCell("" + personService.countOngoing());
    table.addCell("\t\t\t\t\tMissing Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countMissing());
    table.addCell("\t\t\t\t\tFamily Abductions");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countFamilyAbduction());
    table.addCell("\t\t\t\t\tNon-Family Abductions");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countNonFamilyAbduction());
    table.addCell("\t\t\t\t\tRunaway Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countRunaway());
    table.addCell("\t\t\t\t\tUnknown");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnknown());
    table.addCell("\t\t\t\t\tFound Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countFound());
    table.addCell("\t\t\t\t\tAbandoned Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countAbandoned());
    table.addCell("\t\t\t\t\tThrowaway Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countThrowaway());
    table.addCell("\t\t\t\t\tUnidentified");
    table.addCell(
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnidentified());
    table.addCell("Total Solved Cases");
    table.addCell("" + personService.countSolved());
    table.addCell("\t\t\t\t\tMissing Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedMissing());
    table.addCell("\t\t\t\t\tFamily Abductions");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedFamilyAbduction());
    table.addCell("\t\t\t\t\tNon-Family Abductions");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedNonFamilyAbduction());
    table.addCell("\t\t\t\t\tRunaway Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedRunaway());
    table.addCell("\t\t\t\t\tUnknown");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedUnknown());
    table.addCell("\t\t\t\t\tFound Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedFound());
    table.addCell("\t\t\t\t\tAbandoned Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedAbandoned());
    table.addCell("\t\t\t\t\tThrowaway Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedThrowaway());
    table.addCell("\t\t\t\t\tUnidentified");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
            + personService.countSolvedUnidentified());
    table.addCell("Total Unsolved Cases");
    table.addCell("" + personService.countUnsolved());
    table.addCell("\t\t\t\t\tMissing Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedMissing());
    table.addCell("\t\t\t\t\tFamily Abductions");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedFamilyAbduction());
    table.addCell("\t\t\t\t\tNon-Family Abductions");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedNonFamilyAbduction());
    table.addCell("\t\t\t\t\tRunaway Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedRunaway());
    table.addCell("\t\t\t\t\tUnknown");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedUnknown());
    table.addCell("\t\t\t\t\tFound Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedFound());
    table.addCell("\t\t\t\t\tAbandoned Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedAbandoned());
    table.addCell("\t\t\t\t\tThrowaway Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedThrowaway());
    table.addCell("\t\t\t\t\tUnidentified");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
            + personService.countUnsolvedUnidentified());
    table.addCell("Total Cases");
    table.addCell("" + personService.countAllPersons());
    table.addCell("\t\t\t\t\tTotal Missing Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countAllMissing());
    table.addCell("\t\t\t\t\tTotal Found Persons");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countAllFound());
    table.addCell("\t\t\t\t\tTotal Unidentified Persons");
    table.addCell(
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnidentified());
    table.addCell("Total Relatives");
    table.addCell("" + relativeService.countAllRelatives());
    table.addCell("Total Abductors");
    table.addCell("" + abductorService.countAllAbductors());
    document.add(table);
    if (currentUser != null) {
        // List ongoing cases
        document.setHeader(new HeaderFooter(new Phrase("List of ongoing cases as of " + date), false));
        document.newPage();
        float[] widths = { 0.05f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.05f, 0.15f, 0.1f, 0.1f, 0.05f };
        PdfPTable pdfptable = new PdfPTable(widths);
        pdfptable.setWidthPercentage(100);
        pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Nickname", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Middle Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Case Type", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Photo", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Relative", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Abductor", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Investigator", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        List<Person> personList = personService.listOngoing();
        if (personList != null) {
            for (Person person : personList) {
                // Process the photo
                String tokens[] = person.getPhoto().split("\\/");
                String defaultPhotoBasename = "";
                for (int i = 0; i < tokens.length - 1; i++) {
                    defaultPhotoBasename += tokens[i] + File.separator;
                }
                defaultPhotoBasename += tokens[tokens.length - 1];
                String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/")
                        + defaultPhotoBasename;
                Image image = Image.getInstance(absoluteDefaultPhotoFilename);
                image.scaleAbsolute(50, 75);
                image.setAlignment(Image.ALIGN_CENTER);

                pdfptable.addCell(
                        new Phrase("" + person.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getNickname(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getMiddleName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("type." + person.getType()),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("status.case." + person.getStatus()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(image);
                String relativeName = "";
                if (person.getRelativeId() != null) {
                    Relative relative = relativeService.getRelativeById(person.getRelativeId());
                    relativeName = relative.getFirstName() + " " + relative.getLastName();
                }
                pdfptable.addCell(new Phrase(relativeName, FontFactory.getFont(FontFactory.HELVETICA, 8)));
                String abductorName = "";
                if (person.getAbductorId() != null) {
                    Abductor abductor = abductorService.getAbductorById(person.getAbductorId());
                    abductorName = abductor.getFirstName() + " " + abductor.getLastName();
                }
                pdfptable.addCell(new Phrase(abductorName, FontFactory.getFont(FontFactory.HELVETICA, 8)));
                String investigatorUsername = "";
                if (person.getInvestigatorId() != null) {
                    User investigator = userService.getUserById(person.getInvestigatorId());
                    investigatorUsername = investigator.getUsername();
                }
                pdfptable.addCell(
                        new Phrase(investigatorUsername, FontFactory.getFont(FontFactory.HELVETICA, 8)));
            }
        }
        document.add(pdfptable);

        // List solved cases
        document.setHeader(new HeaderFooter(new Phrase("List of solved cases as of " + date), false));
        document.newPage();
        pdfptable = new PdfPTable(widths);
        pdfptable.setWidthPercentage(100);
        pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Nickname", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Middle Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Case Type", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Photo", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Relative", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Abductor", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Investigator", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        personList = personService.listSolved();
        if (personList != null) {
            for (Person person : personList) {
                // Process the photo
                String tokens[] = person.getPhoto().split("\\/");
                String defaultPhotoBasename = "";
                for (int i = 0; i < tokens.length - 1; i++) {
                    defaultPhotoBasename += tokens[i] + File.separator;
                }
                defaultPhotoBasename += tokens[tokens.length - 1];
                String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/")
                        + defaultPhotoBasename;
                Image image = Image.getInstance(absoluteDefaultPhotoFilename);
                image.scaleAbsolute(50, 75);
                image.setAlignment(Image.ALIGN_CENTER);

                pdfptable.addCell(
                        new Phrase("" + person.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getNickname(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getMiddleName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("type." + person.getType()),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("status.case." + person.getStatus()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(image);
                String relativeName = "";
                if (person.getRelativeId() != null) {
                    Relative relative = relativeService.getRelativeById(person.getRelativeId());
                    relativeName = relative.getFirstName() + " " + relative.getLastName();
                }
                pdfptable.addCell(new Phrase(relativeName, FontFactory.getFont(FontFactory.HELVETICA, 8)));
                String abductorName = "";
                if (person.getAbductorId() != null) {
                    Abductor abductor = abductorService.getAbductorById(person.getAbductorId());
                    abductorName = abductor.getFirstName() + " " + abductor.getLastName();
                }
                pdfptable.addCell(new Phrase(abductorName, FontFactory.getFont(FontFactory.HELVETICA, 8)));
                String investigatorUsername = "";
                if (person.getInvestigatorId() != null) {
                    User investigator = userService.getUserById(person.getInvestigatorId());
                    investigatorUsername = investigator.getUsername();
                }
                pdfptable.addCell(
                        new Phrase(investigatorUsername, FontFactory.getFont(FontFactory.HELVETICA, 8)));
            }
        }
        document.add(pdfptable);

        // List unsolved cases
        document.setHeader(new HeaderFooter(new Phrase("List of unsolved cases as of " + date), false));
        document.newPage();
        pdfptable = new PdfPTable(widths);
        pdfptable.setWidthPercentage(100);
        pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Nickname", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Middle Name", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Case Type", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Photo", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Relative", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Abductor", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase("Investigator", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        personList = personService.listUnsolved();
        if (personList != null) {
            for (Person person : personList) {
                // Process the photo
                String tokens[] = person.getPhoto().split("\\/");
                String defaultPhotoBasename = "";
                for (int i = 0; i < tokens.length - 1; i++) {
                    defaultPhotoBasename += tokens[i] + File.separator;
                }
                defaultPhotoBasename += tokens[tokens.length - 1];
                String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/")
                        + defaultPhotoBasename;
                Image image = Image.getInstance(absoluteDefaultPhotoFilename);
                image.scaleAbsolute(50, 75);
                image.setAlignment(Image.ALIGN_CENTER);

                pdfptable.addCell(
                        new Phrase("" + person.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getNickname(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(person.getMiddleName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("type." + person.getType()),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("status.case." + person.getStatus()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(image);
                String relativeName = "";
                if (person.getRelativeId() != null) {
                    Relative relative = relativeService.getRelativeById(person.getRelativeId());
                    relativeName = relative.getFirstName() + " " + relative.getLastName();
                }
                pdfptable.addCell(new Phrase(relativeName, FontFactory.getFont(FontFactory.HELVETICA, 8)));
                String abductorName = "";
                if (person.getAbductorId() != null) {
                    Abductor abductor = abductorService.getAbductorById(person.getAbductorId());
                    abductorName = abductor.getFirstName() + " " + abductor.getLastName();
                }
                pdfptable.addCell(new Phrase(abductorName, FontFactory.getFont(FontFactory.HELVETICA, 8)));
                String investigatorUsername = "";
                if (person.getInvestigatorId() != null) {
                    User investigator = userService.getUserById(person.getInvestigatorId());
                    investigatorUsername = investigator.getUsername();
                }
                pdfptable.addCell(
                        new Phrase(investigatorUsername, FontFactory.getFont(FontFactory.HELVETICA, 8)));
            }
        }
        document.add(pdfptable);
    }
    document.close();

    // Set the response to return the poster (PDF file)
    response.setContentType("application/pdf");
    response.setContentLength(baos.size());
    response.setHeader("Content-disposition", "attachment; filename=Case_Statistics.pdf");

    // Close the output stream
    baos.writeTo(response.getOutputStream());
    response.getOutputStream().flush();

    return null;
}

From source file:com.googlecode.openmpis.action.PersonAction.java

License:Open Source License

/**
 * Prints the person's poster in PDF file.
 *
 * @param mapping       the ActionMapping used to select this instance
 * @param form          the optional ActionForm bean for this request
 * @param request       the HTTP Request we are processing
 * @param response      the HTTP Response we are processing
 * @return              the forwarding instance
 * @throws java.lang.Exception/*from  ww  w.j a va  2s  . c om*/
 */
public ActionForward printPoster(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // Set the paper size and margins
    Document document = new Document(PageSize.LETTER, 50, 50, 50, 50);

    // Create the PDF writer
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    // Retrieve the person
    try {
        int id = Integer.parseInt(request.getParameter("id"));
        Person person = (Person) personService.getPersonById(id);

        // Process the photo
        String tokens[] = person.getPhoto().split("\\/");
        String defaultPhotoBasename = "";
        for (int i = 0; i < tokens.length - 1; i++) {
            defaultPhotoBasename += tokens[i] + File.separator;
        }
        defaultPhotoBasename += tokens[tokens.length - 1];
        String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/")
                + defaultPhotoBasename;

        // Add some meta information to the document
        document.addTitle("Poster");
        document.addAuthor("OpenMPIS");
        document.addSubject("Poster for " + person.getNickname());
        document.addKeywords("OpenMPIS, missing, found, unidentified");
        document.addProducer();
        document.addCreationDate();
        document.addCreator("OpenMPIS version " + Constants.VERSION);

        // Open the document for writing
        document.open();
        // Add the banner
        if (person.getType() > 4) {
            Paragraph foundParagraph = new Paragraph("F O U N D",
                    FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0)));
            foundParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(foundParagraph);
        } else {
            Paragraph missingParagraph = new Paragraph("M I S S I N G",
                    FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0)));
            missingParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(missingParagraph);
        }
        // Add date missing or found
        Paragraph blackParagraph = new Paragraph(
                getResources(request).getMessage("month." + person.getMonthMissingOrFound()) + " "
                        + person.getDayMissingOrFound() + ", " + person.getYearMissingOrFound(),
                FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0)));
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add missing from location
        if (person.getType() < 5) {
            blackParagraph = new Paragraph(person.getMissingFromCity() + ", " + person.getMissingFromProvince(),
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0)));
            blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(blackParagraph);
        }
        // Add name
        Paragraph redParagraph;
        if (!person.getNickname().isEmpty()) {
            redParagraph = new Paragraph(
                    person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
        } else {
            redParagraph = new Paragraph(person.getFirstName() + " " + person.getLastName(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
        }
        redParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(redParagraph);
        // Add the photo
        Image image = Image.getInstance(absoluteDefaultPhotoFilename);
        image.scaleAbsolute(200, 300);
        image.setAlignment(Image.ALIGN_CENTER);
        document.add(image);
        // Add description
        redParagraph = new Paragraph("Description",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
        redParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(redParagraph);
        float[] widths = { 0.5f, 0.5f };
        PdfPTable pdfptable = new PdfPTable(widths);
        pdfptable.setWidthPercentage(100);
        if (person.getType() < 5) {
            pdfptable
                    .addCell(
                            new Phrase(
                                    getResources(request).getMessage("label.date.birth") + ": "
                                            + getResources(request)
                                                    .getMessage("month." + person.getBirthMonth())
                                            + " " + person.getBirthDay() + ", " + person.getBirthYear(),
                                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(
                    new Phrase(getResources(request).getMessage("label.address.city") + ": " + person.getCity(),
                            FontFactory.getFont(FontFactory.HELVETICA, 12)));
        }
        pdfptable.addCell(new Phrase(
                getResources(request).getMessage("label.sex") + ": "
                        + getResources(request).getMessage("sex." + person.getSex()),
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable
                .addCell(
                        new Phrase(
                                getResources(request).getMessage("label.color.hair") + ": "
                                        + getResources(request)
                                                .getMessage("color.hair." + person.getHairColor()),
                                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase(getResources(request).getMessage("label.height") + ": " + person.getFeet()
                + "' " + person.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase(
                getResources(request).getMessage("label.color.eye") + ": "
                        + getResources(request).getMessage("color.eye." + person.getEyeColor()),
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase(
                getResources(request).getMessage("label.weight") + ": " + person.getWeight() + " "
                        + getResources(request).getMessage("label.weight.lbs"),
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        pdfptable.addCell(new Phrase(
                getResources(request).getMessage("label.race") + ": "
                        + getResources(request).getMessage("race." + person.getRace()),
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        document.add(pdfptable);
        // Add circumstance
        redParagraph = new Paragraph(getResources(request).getMessage("label.circumstance"),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
        redParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(redParagraph);
        blackParagraph = new Paragraph(person.getCircumstance(),
                FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL));
        blackParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED);
        document.add(blackParagraph);
        // Add line
        blackParagraph = new Paragraph(
                "------------------------------------------------------------------------------");
        blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(blackParagraph);
        // Add contact
        blackParagraph = new Paragraph(getResources(request).getMessage("global.contact"),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL));
        blackParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED);
        document.add(blackParagraph);
        document.close();

        // Set the response to return the poster (PDF file)
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        response.setHeader("Content-disposition", "attachment; filename=Poster.pdf");

        // Close the output stream
        baos.writeTo(response.getOutputStream());
        response.getOutputStream().flush();

        return null;
    } catch (NumberFormatException nfe) {
        return mapping.findForward(Constants.LIST_PERSON);
    } catch (NullPointerException npe) {
        return mapping.findForward(Constants.LIST_PERSON);
    }
}

From source file:com.googlecode.openmpis.action.ReportAction.java

License:Open Source License

/**
 * Prints the reports.//from w w  w  .  ja v  a  2  s .  c om
 * This is the print report action called from the Struts framework.
 *
 * @param mapping       the ActionMapping used to select this instance
 * @param form          the optional ActionForm bean for this request
 * @param request       the HTTP Request we are processing
 * @param response      the HTTP Response we are processing
 * @return              the forwarding instance
 * @throws java.lang.Exception
 */
public ActionForward printReport(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    User currentUser = null;

    // Check if there exists a session
    if (request.getSession().getAttribute("currentuser") == null) {
        return mapping.findForward(Constants.EXPIRED);
    } else {
        currentUser = (User) request.getSession().getAttribute("currentuser");
    }

    // Check if current user is authorized
    if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) {
        // Retrieve person ID
        try {
            int personId = Integer.parseInt(request.getParameter("personid"));
            Person person = personService.getPersonById(personId);

            // Process the photo
            String tokens[] = person.getPhoto().split("\\/");
            String defaultPhotoBasename = "";
            for (int i = 0; i < tokens.length - 1; i++) {
                defaultPhotoBasename += tokens[i] + File.separator;
            }
            defaultPhotoBasename += tokens[tokens.length - 1];
            String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/")
                    + defaultPhotoBasename;

            // Set the paper size and margins
            Document document = new Document(PageSize.LETTER, 50, 50, 50, 50);

            // Create the PDF writer
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);

            // Add some meta information to the document
            document.addTitle("Progress Report");
            document.addAuthor("OpenMPIS");
            document.addSubject("Progress Report");
            document.addKeywords("OpenMPIS, missing, found, unidentified");
            document.addProducer();
            document.addCreationDate();
            document.addCreator("OpenMPIS version " + Constants.VERSION);

            // Set the header
            String date = simpleDateFormat.format(System.currentTimeMillis());
            document.setHeader(new HeaderFooter(new Phrase("Report for " + person.getFirstName() + " \""
                    + person.getNickname() + "\" " + person.getLastName() + " as of " + date), false));

            // Set the footer
            HeaderFooter footer = new HeaderFooter(new Phrase("Page : "), true);
            footer.setAlignment(Element.ALIGN_CENTER);
            document.setFooter(footer);

            // Open the document for writing
            document.open();
            // Print the information on person
            // Add the banner
            if (person.getType() > 4) {
                Paragraph foundParagraph = new Paragraph("F O U N D",
                        FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0)));
                foundParagraph.setAlignment(Paragraph.ALIGN_CENTER);
                document.add(foundParagraph);
            } else {
                Paragraph missingParagraph = new Paragraph("M I S S I N G",
                        FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0)));
                missingParagraph.setAlignment(Paragraph.ALIGN_CENTER);
                document.add(missingParagraph);
            }
            // Add date missing or found
            Paragraph blackParagraph = new Paragraph(
                    getResources(request).getMessage("month." + person.getMonthMissingOrFound()) + " "
                            + person.getDayMissingOrFound() + ", " + person.getYearMissingOrFound(),
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0)));
            blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(blackParagraph);
            // Add missing from location
            if (person.getType() < 5) {
                blackParagraph = new Paragraph(
                        person.getMissingFromCity() + ", " + person.getMissingFromProvince(),
                        FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0)));
                blackParagraph.setAlignment(Paragraph.ALIGN_CENTER);
                document.add(blackParagraph);
            }
            // Add name
            Paragraph redParagraph;
            if (!person.getNickname().isEmpty()) {
                redParagraph = new Paragraph(
                        person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
            } else {
                redParagraph = new Paragraph(person.getFirstName() + " " + person.getLastName(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
            }
            redParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(redParagraph);
            // Add the photo
            Image image = Image.getInstance(absoluteDefaultPhotoFilename);
            image.scaleAbsolute(200, 300);
            image.setAlignment(Image.ALIGN_CENTER);
            document.add(image);
            // Add description
            redParagraph = new Paragraph("Description",
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0)));
            redParagraph.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(redParagraph);
            float[] widths = { 0.5f, 0.5f };
            PdfPTable pdfptable = new PdfPTable(widths);
            pdfptable.setWidthPercentage(100);
            if (person.getType() < 5) {
                pdfptable
                        .addCell(
                                new Phrase(
                                        getResources(request).getMessage("label.date.birth") + ": "
                                                + getResources(request)
                                                        .getMessage("month." + person.getBirthMonth())
                                                + " " + person.getBirthDay() + ", " + person.getBirthYear(),
                                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(
                        getResources(request).getMessage("label.address.city") + ": " + person.getCity(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
            }
            pdfptable.addCell(new Phrase(
                    getResources(request).getMessage("label.sex") + ": "
                            + getResources(request).getMessage("sex." + person.getSex()),
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable
                    .addCell(
                            new Phrase(
                                    getResources(request).getMessage("label.color.hair") + ": "
                                            + getResources(request)
                                                    .getMessage("color.hair." + person.getHairColor()),
                                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable
                    .addCell(new Phrase(
                            getResources(request).getMessage("label.height") + ": " + person.getFeet() + "' "
                                    + person.getInches() + "\"",
                            FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable
                    .addCell(
                            new Phrase(
                                    getResources(request).getMessage("label.color.eye") + ": "
                                            + getResources(request)
                                                    .getMessage("color.eye." + person.getEyeColor()),
                                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase(
                    getResources(request).getMessage("label.weight") + ": " + person.getWeight() + " "
                            + getResources(request).getMessage("label.weight.lbs"),
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase(
                    getResources(request).getMessage("label.race") + ": "
                            + getResources(request).getMessage("race." + person.getRace()),
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            document.add(pdfptable);

            // Print information on relative
            Relative relative = relativeService.getRelativeById(person.getRelativeId());

            document.newPage();
            document.add(new Paragraph(getResources(request).getMessage("label.relative.name") + ": "
                    + relative.getFirstName() + " " + relative.getLastName()));
            document.add(new Paragraph(getResources(request).getMessage("label.relation") + ": "
                    + getResources(request).getMessage("relation." + person.getRelationToRelative())));
            document.add(new Paragraph(getResources(request).getMessage("label.address") + ": "
                    + relative.getStreet() + ", " + relative.getCity() + ", " + relative.getProvince()));
            document.add(new Paragraph(
                    getResources(request).getMessage("label.number") + ": " + relative.getNumber()));
            document.add(new Paragraph(
                    getResources(request).getMessage("label.email") + ": " + relative.getEmail()));

            // Print information on abductor
            if (person.getAbductorId() != null) {
                Abductor abductor = abductorService.getAbductorById(person.getAbductorId());

                document.newPage();
                document.add(new Paragraph(getResources(request).getMessage("label.abductor.name") + ": "
                        + abductor.getFirstName() + " " + abductor.getLastName()));
            }

            // Print sightings
            if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) {
                document.setHeader(new HeaderFooter(new Phrase("List of sightings as of " + date), false));
                document.newPage();
                float sightingsWidths[] = { 0.1f, 0.1f, 0.1f, 0.3f, 0.1f, 0.1f, 0.1f, 0.1f };
                pdfptable = new PdfPTable(sightingsWidths);
                pdfptable.setWidthPercentage(100);
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.id"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.date.sent"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.subject"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.message"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.lastname"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.firstname"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.email"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.ipaddress"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                List<Message> sightingList = messageService.listAllSightingsForPerson(personId);
                for (Message sighting : sightingList) {
                    pdfptable.addCell(
                            new Phrase("" + sighting.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getSubject(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getMessage(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(sighting.getIpAddress(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                }
                document.add(pdfptable);
            }

            // Print progress reports
            if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) {
                document.setHeader(
                        new HeaderFooter(new Phrase("List of progress reports as of " + date), false));
                document.newPage();
                float reportsWidths[] = { 0.1f, 0.1f, 0.3f };
                pdfptable = new PdfPTable(reportsWidths);
                pdfptable.setWidthPercentage(100);
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.id"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.date.reported"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("label.report"),
                        FontFactory.getFont(FontFactory.HELVETICA, 12)));
                List<Report> reportList = reportService.listAllReportsForPerson(personId);
                for (Report report : reportList) {
                    pdfptable.addCell(
                            new Phrase("" + report.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(report.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                    pdfptable.addCell(
                            new Phrase(report.getReport(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                }
                document.add(pdfptable);
            }
            document.close();

            // Set the response to return the poster (PDF file)
            response.setContentType("application/pdf");
            response.setContentLength(baos.size());
            response.setHeader("Content-disposition", "attachment; filename=Report.pdf");

            // Close the output stream
            baos.writeTo(response.getOutputStream());
            response.getOutputStream().flush();

            return null;
        } catch (NumberFormatException nfe) {
            return mapping.findForward(Constants.LIST_PERSON);
        } catch (NullPointerException npe) {
            return mapping.findForward(Constants.LIST_PERSON);
        }
    } else {
        return mapping.findForward(Constants.UNAUTHORIZED);
    }
}

From source file:com.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java

public void onStartArRedInvoicePage(PdfWriter writer, Document document) {
    try {//from   w  w  w. j  a v  a2s  .  c om
        SystemRulesDAO systemRulesDAO = new SystemRulesDAO();
        String companyAddress = systemRulesDAO.getSystemRulesByCode("CompanyAddress");
        String companyPhone = systemRulesDAO.getSystemRulesByCode("CompanyPhone");
        String companyFax = systemRulesDAO.getSystemRulesByCode("CompanyFax");
        PdfPCell cell = new PdfPCell();
        PdfPTable headingMainTable = new PdfPTable(1);
        headingMainTable.setWidthPercentage(100);
        PdfPTable headingTable = new PdfPTable(1);
        headingTable.setWidths(new float[] { 100 });
        PdfPTable imgTable = new PdfPTable(1);
        imgTable.setWidthPercentage(100);
        Image img = null;
        String logoImage = "";
        String brand = this.setBrand(fileNumberId);
        if (CommonUtils.isNotEmpty(brand)) {
            if ("ECI".equalsIgnoreCase(brand)) {
                logoImage = LoadLogisoftProperties.getProperty("application.image.econo.logo");
                img = Image.getInstance(realPath + logoImage);
                img.scalePercent(75);
            } else if ("OTI".equalsIgnoreCase(brand)) {
                logoImage = LoadLogisoftProperties.getProperty("application.image.econo.logo");
                img = Image.getInstance(realPath + logoImage);
                img.scalePercent(45);
            } else {
                logoImage = LoadLogisoftProperties.getProperty("application.image.logo");
                img = Image.getInstance(realPath + logoImage);
                img.scalePercent(45);
            }
        }
        img.scalePercent(75);
        PdfPCell logoCell = new PdfPCell(img);
        logoCell.setBorder(Rectangle.NO_BORDER);
        logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        logoCell.setVerticalAlignment(Element.ALIGN_LEFT);
        logoCell.setPaddingLeft(+27);
        imgTable.addCell(logoCell);
        PdfPTable addrTable = new PdfPTable(1);
        addrTable.setWidthPercentage(100);
        PdfPTable invoiceFacturaTable = new PdfPTable(3);
        invoiceFacturaTable.setWidthPercentage(100);
        invoiceFacturaTable.setWidths(new float[] { 40, 20, 40 });
        StringBuilder stringBuilder = new StringBuilder();
        addrTable.addCell(makeCellCenterNoBorderFclBL("MAILING ADDRESS: "
                + (CommonUtils.isNotEmpty(companyAddress) ? companyAddress.toUpperCase() : "")));
        stringBuilder.append("TEL: ");
        stringBuilder.append(CommonUtils.isNotEmpty(companyPhone) ? companyPhone : "").append(" / ");
        stringBuilder.append("FAX: ");
        stringBuilder.append(CommonUtils.isNotEmpty(companyFax) ? companyFax : "");
        addrTable.addCell(makeCellCenterNoBorderFclBL(stringBuilder.toString()));
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));
        invoiceFacturaTable.addCell(makeCellLeftNoBorderFclBL(""));
        cell = makeCell("INVOICE", Element.ALIGN_CENTER, new Font(Font.HELVETICA, 12, Font.BOLD, Color.RED),
                0.06f);
        invoiceFacturaTable.addCell(cell);
        invoiceFacturaTable.addCell(makeCellLeftNoBorderFclBL(""));
        cell = new PdfPCell();
        cell.addElement(invoiceFacturaTable);
        cell.setBorder(0);
        addrTable.addCell(cell);
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));

        cell = new PdfPCell();
        cell.addElement(imgTable);
        cell.setBorder(0);
        cell.setPaddingLeft(+150);
        headingMainTable.addCell(cell);
        //            headingTable.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(addrTable);
        cell.setBorder(0);
        headingTable.addCell(cell);
        cell = makeCellLeftNoBorderFclBL("");
        cell.setBorderWidthRight(0.06f);
        cell.setBorderWidthLeft(0.06f);
        cell.setBorderWidthTop(0.06f);
        cell.setBorderWidthBottom(0.0f);
        cell.addElement(headingTable);
        headingMainTable.addCell(cell);
        document.add(headingMainTable);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:com.gp.cong.logisoft.reports.BookingCoverSheetPdfCreater.java

public void createBody(SearchBookingReportDTO searchBookingReportDTO, String simpleRequest,
        MessageResources messageResources, String printFromBl, String documentName)
        throws DocumentException, MalformedURLException, IOException, Exception {
    NumberFormat numformat = new DecimalFormat("##,###,##0.00");
    PdfPCell cell = new PdfPCell();
    Paragraph paragraph;/*ww  w .j  a va  2 s . c om*/
    PdfPTable table;
    Phrase phrase;

    PdfPTable mainTable = makeTable(2);
    mainTable.setWidthPercentage(100);

    BookingFcl bookingFcl = searchBookingReportDTO.getBookingflFcl();
    FclBl fclBl = null;
    if (CommonUtils.isNotEmpty(printFromBl)) {
        fclBl = new FclBlDAO().getFileNoObject(bookingFcl.getFileNo());
    }
    String company = null;
    String contactName = "";
    String email = null;
    String phone = null;
    String fax = null;
    String address = null;
    QuotationDAO quotationDAO = new QuotationDAO();
    CustAddressBC custAddressBC = new CustAddressBC();
    Quotation quotation = quotationDAO.getFileNoObject(bookingFcl.getFileNo());
    if (null != quotation) {
        contactName = quotation.getContactname();
    }
    if (bookingFcl.getShippercheck() != null && bookingFcl.getShippercheck().equals("on")) {
        //from=bookingFcl.getShipper();
        company = bookingFcl.getShipper();
        email = bookingFcl.getShipperEmail();
        phone = bookingFcl.getShipperPhone();
        fax = bookingFcl.getShipperFax();
        address = bookingFcl.getAddressforShipper();
    } else if (bookingFcl.getForwardercheck() != null && bookingFcl.getForwardercheck().equals("on")) {
        company = bookingFcl.getForward();
        email = bookingFcl.getForwarderEmail();
        phone = bookingFcl.getForwarderPhone();
        fax = bookingFcl.getForwarderFax();
        address = bookingFcl.getAddressforForwarder();
    } else if (bookingFcl.getConsigneecheck() != null && bookingFcl.getConsigneecheck().equals("on")) {
        company = bookingFcl.getConsignee();
        email = bookingFcl.getConsingeeEmail();
        phone = bookingFcl.getConsingeePhone();
        fax = bookingFcl.getConsigneeFax();
        address = bookingFcl.getAddressforConsingee();
    } else {
        if (null != quotation) {
            company = quotation.getClientname();
            email = quotation.getEmail1();
            phone = quotation.getPhone();
            fax = quotation.getFax();
            CustAddress custAddress = custAddressBC.getClientAddress(quotation.getClientnumber());
            if (null != custAddress) {
                address = custAddress.getAddress1();
            }
        }
    }

    PdfPTable headerTable = makeTable(3);
    headerTable.setWidths(new float[] { 20, 50, 30 });
    headerTable.setWidthPercentage(100);

    PdfPTable headerTable1 = makeTable(1);
    headerTable1.setWidths(new float[] { 100 });
    headerTable1.setWidthPercentage(100);

    PdfPCell headingCell1 = makeCell(
            new Phrase(messageResources.getMessage("fileNumberPrefix") + String.valueOf(bookingFcl.getFileNo()),
                    headingFont1),
            Element.ALIGN_CENTER);
    headingCell1.setBackgroundColor(Color.LIGHT_GRAY);
    headingCell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerTable1.addCell(headingCell1);
    cell = makeCellleftNoBorder("");
    cell.addElement(headerTable1);
    headerTable.addCell(headerTable1);

    PdfPTable headerTable2 = makeTable(2);
    headerTable2.setWidths(new float[] { 38, 62 });
    headerTable2.setWidthPercentage(100);

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
    SimpleDateFormat sdfForddMMyyyy = new SimpleDateFormat("dd-MMM-yyyy");
    String colon = ": ";
    String docCut = "";
    String carrierDocCut = "";
    String etd = "";
    String eta = "";
    if (bookingFcl.getDocCutOff() != null) {
        docCut = sdf.format(bookingFcl.getDocCutOff());
    }
    if (bookingFcl.getCarrierDocCut() != null) {
        carrierDocCut = sdf.format(bookingFcl.getCarrierDocCut());
    }
    if (bookingFcl.getEtd() != null) {
        etd = sdfForddMMyyyy.format(bookingFcl.getEtd());
    }
    if (bookingFcl.getEta() != null) {
        eta = sdfForddMMyyyy.format(bookingFcl.getEta());
    }

    headerTable2.addCell(makeCell(new Phrase("Doc Cutoff", headingFont2), Element.ALIGN_LEFT));
    headerTable2.addCell(makeCell(new Phrase(colon + docCut, redBoldFont), Element.ALIGN_LEFT));
    headerTable2.addCell(makeCell(new Phrase("Carrier Doc Cut", headingFont2), Element.ALIGN_LEFT));
    headerTable2.addCell(makeCell(new Phrase(colon + carrierDocCut, redBoldFont), Element.ALIGN_LEFT));

    cell = makeCellleftNoBorder("");
    cell.addElement(headerTable2);
    headerTable.addCell(headerTable2);

    PdfPTable headerTable3 = makeTable(2);
    headerTable3.setWidths(new float[] { 20, 80 });
    headerTable3.setWidthPercentage(100);

    headerTable3.addCell(makeCell(new Phrase("ETD", headingFont2), Element.ALIGN_LEFT));
    headerTable3.addCell(makeCell(new Phrase(colon + etd, headingFont2), Element.ALIGN_LEFT));
    headerTable3.addCell(makeCell(new Phrase("ETA", headingFont2), Element.ALIGN_LEFT));
    headerTable3.addCell(makeCell(new Phrase(colon + eta, headingFont2), Element.ALIGN_LEFT));

    cell = makeCellleftNoBorder("");
    cell.addElement(headerTable3);
    headerTable.addCell(headerTable3);

    document.add(headerTable);

    PdfPTable pTable = new PdfPTable(2);
    pTable.setWidthPercentage(100);

    PdfPTable clientTable = makeTable(2);
    clientTable.setWidths(new float[] { 27, 73 });
    clientTable.setWidthPercentage(100);

    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Client Name"));
    clientTable.addCell(makeCellLeftNoBorderValue(company));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Client Address"));
    clientTable.addCell(makeCellLeftNoBorderValue(address));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Name"));
    clientTable.addCell(makeCellLeftNoBorderValue(contactName));
    cell = makeCellleftNoBorderWithBoldFont("Contact Number");
    cell.setNoWrap(true);
    clientTable.addCell(cell);
    clientTable.addCell(makeCellLeftNoBorderValue(phone));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Fax"));
    clientTable.addCell(makeCellLeftNoBorderValue(fax));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Email"));
    clientTable.addCell(makeCellLeftNoBorderValue(email));

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthRight(0.6f);
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthLeft(0.6f);
    cell.setBorderWidthTop(0.6f);
    cell.addElement(clientTable);
    pTable.addCell(cell);

    PdfPTable carrierTable = makeTable(2);
    carrierTable.setWidths(new float[] { 26, 74 });
    carrierTable.setWidthPercentage(100);
    String sslName[] = bookingFcl.getSslname().split("//");

    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Carrier"));
    carrierTable.addCell(makeCellLeftNoBorderValue(sslName.length > 1 ? sslName[0] : ""));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Vessel"));
    carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getVessel()));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Voyage"));
    carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getVoyageCarrier()));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("SSL Booking#"));
    carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getSSBookingNo()));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POO"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getOriginTerminal())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POL"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getPortofOrgin())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POD"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getDestination())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("FD"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getPortofDischarge())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Containers"));
    carrierTable.addCell(makeCellLeftNoBorderValue(
            this.getContainers(simpleRequest, searchBookingReportDTO, messageResources).getContent()));
    //        PdfPCell cell1 = makeCell(this.getContainers(simpleRequest, searchBookingReportDTO, messageResources), 1);
    //        cell1.setColspan(2);
    //        cell1.setBorderWidthLeft(0.0F);
    //        carrierTable.addCell(cell1);

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthRight(0.6f);
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthTop(0.6f);
    cell.addElement(carrierTable);

    pTable.addCell(cell);

    document.add(pTable);

    PdfPTable hazardsMainTable = makeTable(1);
    hazardsMainTable.setWidths(new float[] { 100 });
    hazardsMainTable.setWidthPercentage(100);

    PdfPTable hazardsTable = makeTable(3);
    hazardsTable.setWidths(new float[] { 70, 15, 15 });
    hazardsTable.setWidthPercentage(100);

    Image yes = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/y.png");
    yes.scalePercent(60);
    yes.scaleAbsoluteWidth(18);
    PdfPCell yesCell = new PdfPCell();
    yesCell.setBorder(0);
    yesCell.addElement(new Chunk(yes, 32, -0));

    Image no = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/n.png");
    no.scalePercent(60);
    no.scaleAbsoluteWidth(18);
    PdfPCell noCell = new PdfPCell();
    noCell.setBorder(0);
    noCell.addElement(new Chunk(no, 32, -0));

    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("HAZARDOUS"));
    if (bookingFcl.getHazmat() != null && "Y".equalsIgnoreCase(bookingFcl.getHazmat())) {
        hazardsTable.addCell(yesCell);
        hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), 1));
    } else {
        hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), 1));
        hazardsTable.addCell(noCell);
    }
    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("AES"));
    hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), Element.ALIGN_CENTER));
    hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), Element.ALIGN_CENTER));
    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("DIRECT CONSIGMENT"));
    if (bookingFcl.getDirectConsignmntCheck() != null
            && "on".equalsIgnoreCase(bookingFcl.getDirectConsignmntCheck())) {
        hazardsTable.addCell(yesCell);
        hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), 1));
    } else {
        hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), 1));
        hazardsTable.addCell(noCell);
    }
    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("AFR"));
    hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), Element.ALIGN_CENTER));
    hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), Element.ALIGN_CENTER));

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthRight(0.6f);
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthLeft(0.6f);
    cell.addElement(hazardsTable);

    hazardsMainTable.addCell(cell);
    document.add(hazardsMainTable);

    PdfPTable docsMainTable = makeTable(2);
    docsMainTable.setWidths(new float[] { 30, 70 });
    docsMainTable.setWidthPercentage(100);

    PdfPTable docsTable = makeTable(2);
    docsTable.setWidths(new float[] { 50, 50 });
    docsTable.setWidthPercentage(100);

    Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/uncheckedBox.png");
    img.scalePercent(50);
    img.scaleAbsoluteWidth(18);
    PdfPCell pCell = new PdfPCell();
    pCell.setBorder(0);
    pCell.addElement(new Chunk(img, 25, -0));

    //        Image checkedimg = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/check.png");
    //        checkedimg.scalePercent(60);
    //        checkedimg.scaleAbsoluteWidth(18);
    //        PdfPCell checkedCell = new PdfPCell();
    //        checkedCell.setBorder(0);
    //        checkedCell.addElement(new Chunk(checkedimg, 25, -0));
    docsTable.addCell(makeCellleftNoBorderWithBoldFont("Docs"));
    docsTable.addCell(pCell);

    docsTable.addCell(makeCellNoBorders("       "));
    docsTable.addCell(makeCellNoBorders("       "));

    docsTable.addCell(makeCellleftNoBorderWithBoldFont("COB"));
    docsTable.addCell(pCell);

    docsTable.addCell(makeCellNoBorders("       "));
    docsTable.addCell(makeCellNoBorders("       "));

    docsTable.addCell(makeCellleftNoBorderWithBoldFont("MBL"));
    docsTable.addCell(pCell);

    docsTable.addCell(makeCellNoBorders("       "));
    docsTable.addCell(makeCellNoBorders("       "));

    docsTable.addCell(makeCellleftNoBorderWithBoldFont("Manifisted"));
    docsTable.addCell(pCell);

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthLeft(0.6f);
    cell.addElement(docsTable);
    docsMainTable.addCell(cell);

    PdfPTable noteTable = makeTable(1);
    noteTable.setWidths(new float[] { 100 });
    noteTable.setWidthPercentage(100);
    noteTable.addCell(makeCellCenterNoBorder("Notes"));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthRight(0.6f);
    cell.addElement(noteTable);
    docsMainTable.addCell(cell);
    document.add(docsMainTable);

}

From source file:com.gp.cong.logisoft.reports.BookingCoverSheetPdfCreater.java

public void onStartPage(PdfWriter writer, Document document) {
    try {//from  w w  w  . j a  va2 s  . c  o m

        PdfPCell cell = new PdfPCell();
        PdfPCell celL = new PdfPCell();
        PdfPTable table = new PdfPTable(1);
        FclBl fclBl = null;
        String brand = "";
        String path = LoadLogisoftProperties.getProperty("application.image.logo");
        String econoPath = LoadLogisoftProperties.getProperty("application.image.econo.logo");
        String companyCode = new SystemRulesDAO().getSystemRulesByCode("CompanyCode");
        BookingFcl bookingFcl = searchBookingReportDTO.getBookingflFcl();
        fclBl = new FclBlDAO().getOriginalBl(bookingFcl.getFileNo());
        if (null != fclBl && null != fclBl.getBrand()) {
            brand = fclBl.getBrand();
        } else if (null != bookingFcl && null != bookingFcl.getBrand()) {
            brand = bookingFcl.getBrand();
        }
        if (brand.equals("Econo") && ("03").equals(companyCode)) {
            Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + econoPath);
            table.setWidthPercentage(100);
            img.scalePercent(60);
            //img.scaleAbsoluteWidth(200);
            celL.addElement(new Chunk(img, 180, -20));
            celL.setBorder(0);
            celL.setHorizontalAlignment(Element.ALIGN_CENTER);
            celL.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(celL);
            //            DateFormat df7 = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
            //            Date currentDate = new Date();
            //            cell = makeCellRightNoBorder("Date Printed : " + df7.format(currentDate));
            cell = makeCellRightNoBorder("  ");
            cell.setPaddingTop(10f);
            table.addCell(cell);
        } else if (brand.equals("OTI") && ("02").equals(companyCode)) {
            Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + econoPath);
            table.setWidthPercentage(100);
            img.scalePercent(60);
            //img.scaleAbsoluteWidth(200);
            celL.addElement(new Chunk(img, 180, -20));
            celL.setBorder(0);
            celL.setHorizontalAlignment(Element.ALIGN_CENTER);
            celL.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(celL);
            //            DateFormat df7 = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
            //            Date currentDate = new Date();
            //            cell = makeCellRightNoBorder("Date Printed : " + df7.format(currentDate));
            cell = makeCellRightNoBorder("  ");
            cell.setPaddingTop(10f);
            table.addCell(cell);
        } else if (brand.equalsIgnoreCase("Ecu Worldwide")) {
            Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + path);
            table.setWidthPercentage(100);
            img.scalePercent(60);
            //img.scaleAbsoluteWidth(200);
            celL.addElement(new Chunk(img, 180, -20));
            celL.setBorder(0);
            celL.setHorizontalAlignment(Element.ALIGN_CENTER);
            celL.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(celL);
            //            DateFormat df7 = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
            //            Date currentDate = new Date();
            //            cell = makeCellRightNoBorder("Date Printed : " + df7.format(currentDate));
            cell = makeCellRightNoBorder("  ");
            cell.setPaddingTop(10f);
            table.addCell(cell);
        }

        // table for heading
        //            PdfPTable heading = makeTable(1);
        //            heading.setWidthPercentage(100);            
        //             heading.addCell(makeCellCenterForDoubleHeading("FCL Booking Confirmation " + messageResources.getMessage("fileNumberPrefix") + String.valueOf(bookingFcl.getFileNo())));
        //            
        document.add(table);
        //            document.add(heading);
    } catch (Exception e) {
        log.info("onStartPage failed on " + new Date(), e);
        throw new ExceptionConverter(e);
    }
}