Example usage for com.lowagie.text Table endHeaders

List of usage examples for com.lowagie.text Table endHeaders

Introduction

In this page you can find the example usage for com.lowagie.text Table endHeaders.

Prototype

public int endHeaders() 

Source Link

Document

Marks the last row of the table headers.

Usage

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private Object generateElementHtml(Element element, int depth, Font font) {
    String tag = element.getName();
    Object myself;//  www .  jav  a  2 s  .  com
    Object av;
    if (element instanceof HTMLDocument.RunElement) {
        HTMLDocument.RunElement re = (HTMLDocument.RunElement) element;
        int start = re.getStartOffset();
        int end = re.getEndOffset();
        try {
            String content = re.getDocument().getText(start, end - start);
            HtmlAttr htmlattr = printAttributesHtml(re);
            av = re.getAttribute(CSS.Attribute.FONT_SIZE);
            String fontsize = av == null ? null : av.toString();
            av = re.getAttribute(CSS.Attribute.FONT_FAMILY);
            String fontfamily = av == null ? null : av.toString();
            av = re.getAttribute(CSS.Attribute.COLOR);
            String fontcolor = av == null ? null : av.toString();
            if (fontcolor != null || fontsize != null || fontfamily != null) {
                if (fontfamily == null)
                    fontfamily = font.getFamilyname();
                if (fontsize != null && fontsize.endsWith("pt"))
                    fontsize = fontsize.substring(0, fontsize.indexOf("pt"));
                float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8);
                int style = font.getStyle();
                Color color;
                if (fontcolor != null) {
                    color = Color.decode(fontcolor);
                } else
                    color = font.getColor();
                font = FontFactory.getFont(fontfamily, size, style, color);
            } else if (htmlattr.bold || htmlattr.italic) {
                String family = font.getFamilyname();
                float size = font.getSize();
                Color color = font.getColor();
                if (htmlattr.bold && htmlattr.italic)
                    font = FontFactory.getFont(family, size, Font.BOLDITALIC, color);
                else if (htmlattr.italic)
                    font = FontFactory.getFont(family, size, Font.ITALIC, color);
                else if (htmlattr.bold)
                    font = FontFactory.getFont(family, size, Font.BOLD);
            }
            myself = new Chunk(content, font);
        } catch (BadLocationException e) {
            e.printStackTrace();
            myself = null;
        }
    } else if (element instanceof HTMLDocument.BlockElement) {
        HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element;
        HtmlAttr htmlattr = printAttributesHtml(be);
        if (htmlattr.bold) {
            System.out.println("+++BOLD!!!");
        }
        av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN);
        String align = av == null ? null : av.toString();
        if (htmlattr.bold || htmlattr.italic) {
            String family = font.getFamilyname();
            float size = font.getSize();
            Color color = font.getColor();
            if (htmlattr.bold && htmlattr.italic)
                font = FontFactory.getFont(family, size, Font.BOLDITALIC, color);
            else if (htmlattr.italic)
                font = FontFactory.getFont(family, size, Font.ITALIC, color);
            else if (htmlattr.bold)
                font = FontFactory.getFont(family, size, Font.BOLD, Color.blue);
        }
        if (tag.equalsIgnoreCase("html")) {
            myself = generateElementChildrenHtml(element, depth + 1, font);
        } else if (tag.equalsIgnoreCase("head")) {
            myself = null;
        } else if (tag.equalsIgnoreCase("body")) {
            myself = generateElementChildrenHtml(element, depth + 1, font);
        } else if (tag.equalsIgnoreCase("p") || tag.equalsIgnoreCase("p-implied")) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            Paragraph paragraph = new Paragraph();
            paragraph.setFirstLineIndent(0F);
            for (Object child : children) {
                if (child instanceof Chunk) {
                    Chunk chunk = (Chunk) child;
                    /*if (!chunk.getContent().equals("\n"))*/ paragraph.add(chunk);
                } else
                    paragraph.add(child);
            }
            if (align != null)
                paragraph.setAlignment(align);
            myself = paragraph;
        } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont);
            Paragraph title = new Paragraph();
            for (Object child : children) {
                title.add(child);
            }
            myself = new TempSectionPdf(title);
        } else if (tag.equalsIgnoreCase("ul")) {
            com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
            list.setIndentationLeft(25.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                list.add(child);
            }
            myself = list;
        } else if (tag.equalsIgnoreCase("ol")) {
            com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f);
            list.setIndentationLeft(25.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                list.add(child);
            }
            myself = list;
        } else if (tag.equalsIgnoreCase("li")) {
            ListItem li = new ListItem();
            li.setSpacingAfter(0.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                li.add(child);
            }
            myself = li;
        } else if (tag.equalsIgnoreCase("table")) {
            List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont);
            try {
                int ncols = 0;
                for (Object row : rows) {
                    if (row instanceof List<?>) {
                        int n = ((List<?>) row).size();
                        if (n > ncols)
                            ncols = n;
                    }
                }
                Table table = new Table(2);
                table.setBorderWidth(1);
                table.setBorderColor(new Color(0, 128, 128));
                table.setPadding(1.0f);
                table.setSpacing(0.5f);
                Cell c = new Cell("header");
                c.setHeader(true);
                c.setColspan(ncols);
                table.addCell(c);
                table.endHeaders();
                for (Object row : rows) {
                    if (row instanceof List<?>) {
                        for (Object cell : (List<?>) row) {
                            if (cell instanceof Cell)
                                table.addCell((Cell) cell);
                        }
                    }
                }
                myself = table;
            } catch (BadElementException e) {
                e.printStackTrace();
                myself = null;
            }
        } else if (tag.equalsIgnoreCase("tr")) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            myself = children;
        } else if (tag.equalsIgnoreCase("td")) {
            Cell cell = new Cell();
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                cell.add(child);
            }
            myself = cell;
        } else if (tag.equalsIgnoreCase("div")) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            Paragraph paragraph = new Paragraph();
            paragraph.setFirstLineIndent(0F);
            for (Object child : children) {
                paragraph.add(child);
            }
            if (align != null)
                paragraph.setAlignment(align);
            myself = paragraph;
        } else {
            System.err.println("Unknown element " + element.getName());
            myself = null;
        }
    } else {
        myself = null; // could be BidiElement - not sure what it is
    }
    return myself;
}

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

License:Open Source License

/**
 * Writes the cases to a PDF file.//from  w w w. j a  v  a2s.  c o  m
 *
 * @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.UserAction.java

License:Open Source License

/**
 * Writes the users to a PDF file.//from  w w  w .  j  a v a 2s.  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 printUsers(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("List of users 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.setPadding(2);
    table.setSpacing(0);
    Paragraph paragraph = new Paragraph("Users", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD));
    paragraph.setAlignment(Paragraph.ALIGN_CENTER);
    Cell cell = new Cell(paragraph);
    cell.setHeader(true);
    cell.setColspan(2);
    table.addCell(cell);
    table.endHeaders();
    table.addCell("Total Administrators");
    table.addCell("" + userService.countAdministrators());
    table.addCell("\t\t\t\t\tActive Administrators");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveAdministrators());
    table.addCell("\t\t\t\t\tSuspended Administrators");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedAdministrators());
    table.addCell("Total Encoders");
    table.addCell("" + userService.countEncoders());
    table.addCell("\t\t\t\t\tActive Encoders");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveEncoders());
    table.addCell("\t\t\t\t\tSuspended Encoders");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedEncoders());
    table.addCell("Total Investigators");
    table.addCell("" + userService.countInvestigators());
    table.addCell("\t\t\t\t\tActive Investigators");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveInvestigators());
    table.addCell("\t\t\t\t\tSuspended Investigators");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedInvestigators());
    table.addCell("Total Users");
    table.addCell("" + userService.countAllUsers());
    table.addCell("\t\t\t\t\tTotal Active Users");
    table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveUsers());
    table.addCell("\t\t\t\t\tTotal Suspended Users");
    table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedUsers());
    document.add(table);
    if (currentUser != null) {
        if ((currentUser.getGroupId() == 0) || (currentUser.getGroupId() == 1)) {
            // List administrators
            document.setHeader(new HeaderFooter(new Phrase("List of administrators as of " + date), false));
            document.newPage();
            float[] widths = { 0.03f, 0.07f, 0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.05f };
            PdfPTable pdfptable = new PdfPTable(widths);
            pdfptable.setWidthPercentage(100);
            pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Group", 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("Agency", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Designation", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("E-mail Address", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            List<User> administratorList = userService.listAdministrators();
            for (User administrator : administratorList) {
                pdfptable.addCell(
                        new Phrase("" + administrator.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("group." + administrator.getGroupId()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(administrator.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(administrator.getFirstName(),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(administrator.getAgency(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(administrator.getDesignation(),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(administrator.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("status.user." + administrator.getStatus()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
            }
            document.add(pdfptable);

            // List encoders
            document.setHeader(new HeaderFooter(new Phrase("List of encoders 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("Group", 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("Agency", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Designation", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("E-mail Address", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            List<User> encoderList = userService.listEncoders();
            for (User encoder : encoderList) {
                pdfptable.addCell(
                        new Phrase("" + encoder.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(getResources(request).getMessage("group." + encoder.getGroupId()),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(encoder.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(encoder.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(encoder.getAgency(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(encoder.getDesignation(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable
                        .addCell(new Phrase(encoder.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("status.user." + encoder.getStatus()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
            }
            document.add(pdfptable);

            // List investigators
            document.setHeader(new HeaderFooter(new Phrase("List of investigators 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("Group", 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("Agency", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Designation", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("E-mail Address", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            List<User> investigatorList = userService.listInvestigators();
            for (User investigator : investigatorList) {
                pdfptable.addCell(
                        new Phrase("" + investigator.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("group." + investigator.getGroupId()),
                                FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(investigator.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(investigator.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(investigator.getAgency(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(new Phrase(investigator.getDesignation(),
                        FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(investigator.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                pdfptable.addCell(
                        new Phrase(getResources(request).getMessage("status.user." + investigator.getStatus()),
                                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=User_Statistics.pdf");

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

    return null;
}

From source file:de.maklerpoint.office.Schnittstellen.PDF.ExportListePDF.java

License:Open Source License

public void write() throws DocumentException, FileNotFoundException {

    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    Document doc = null;//w  ww.ja  v  a  2  s .com

    if (titles.length > 7)
        doc = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    else
        doc = new Document(PageSize.A4, 20, 20, 20, 20);

    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
    doc.addAuthor("MaklerPoint - www.maklerpoint.de");
    doc.addCreator("MaklerPoint - www.maklerpoint.de");
    doc.addCreationDate();
    doc.addTitle(title);

    doc.open();

    doc.add(new Paragraph(title, FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, Color.BLACK)));

    Table t = new Table(titles.length, data.length + 1);
    t.setPadding(3);
    t.setSpacing(0);
    t.setBorderWidth(1);

    for (int i = 0; i < titles.length; i++) {
        Cell c1 = new Cell(titles[i]);
        c1.setHeader(true);
        t.addCell(c1);
    }
    t.endHeaders();

    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[i].length; j++) {
            Cell c1 = null;
            if (data[i][j] != null)
                c1 = new Cell(data[i][j].toString());
            else
                c1 = new Cell("");
            t.addCell(c1);
        }
    }

    doc.add(t);

    if (footer == null) {
        doc.add(new Paragraph(
                ("Export " + title + " - Genereriert am " + df.format(new Date(System.currentTimeMillis())))
                        + " von MaklerPoint",
                FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    } else {
        doc.add(new Paragraph(footer, FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    }

    doc.close();
}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu des headers./*from   w  ww.ja v  a 2  s.  c om*/
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private static void renderHeaders(final ExportSheet parameters, final Table datatable)
        throws BadElementException {
    // size of columns
    // datatable.setWidths(headerwidths);
    // datatable.setWidth(100f);

    // table header
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    // datatable.getDefaultCell().setGrayFill(0.75f);

    for (final ExportField exportColumn : parameters.getExportFields()) {
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), font));
    }
    // end of the table header
    datatable.endHeaders();
}

From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu des headers./*from w w w  .j  a v a2s .  c  o m*/
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private static void renderHeaders(final ExportSheet parameters, final Table datatable)
        throws BadElementException {
    // table header
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    for (final ExportField exportColumn : parameters.getExportFields()) {
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), font));
    }
    // end of the table header
    datatable.endHeaders();
}

From source file:net.bull.javamelody.swing.print.MPdfWriter.java

License:Apache License

/**
 * Effectue le rendu des headers./*from   w w  w.j ava  2 s  .  c o m*/
 *
 * @param table
 *           MBasicTable
 * @param datatable
 *           Table
 * @throws BadElementException
 *            e
 */
protected void renderHeaders(final MBasicTable table, final Table datatable) throws BadElementException {
    final int columnCount = table.getColumnCount();
    final TableColumnModel columnModel = table.getColumnModel();
    // size of columns
    float totalWidth = 0;
    for (int i = 0; i < columnCount; i++) {
        totalWidth += columnModel.getColumn(i).getWidth();
    }
    final float[] headerwidths = new float[columnCount];
    for (int i = 0; i < columnCount; i++) {
        headerwidths[i] = 100f * columnModel.getColumn(i).getWidth() / totalWidth;
    }
    datatable.setWidths(headerwidths);
    datatable.setWidth(100f);

    // table header
    final com.lowagie.text.Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    // datatable.setDefaultCellGrayFill(0.75f);

    String text;
    Object value;
    for (int i = 0; i < columnCount; i++) {
        value = columnModel.getColumn(i).getHeaderValue();
        text = value != null ? value.toString() : "";
        datatable.addCell(new Phrase(text, font));
    }
    // end of the table header
    datatable.endHeaders();
}

From source file:opisiame.controller.gestion_resultat.Choix_exportController.java

@FXML
public void pdf_export() {
    File pdf_file = choix_chemin_enregistrement("PDF files (*.pdf)", "*.pdf");

    if (onglet_actif.equals("questions")) {

        if (pdf_file != null) {
            Document document = new Document(PageSize.A4);
            try {
                PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
                document.open();/* www  .  j a  v  a  2s .  c o m*/
                document.add(new Paragraph("Rsultat Quiz"));

                Table tableau = new Table(6, reponse_questions.size());
                tableau.setAutoFillEmptyCells(true);
                tableau.setPadding(2);

                Cell cell = new Cell("Question");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse A");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse B");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse C");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse D");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage bonne rponse");
                cell.setHeader(true);
                tableau.addCell(cell);

                tableau.endHeaders();
                tableau.setWidth(100);
                fill_data_pdf(tableau);
                document.add(tableau);
            } catch (DocumentException | IOException de) {
                de.printStackTrace();
            }
            document.close();
        }

    } else if (onglet_actif.equals("eleves")) {

        if (pdf_file != null) {
            Document document = new Document(PageSize.A4);
            try {
                PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
                document.open();
                document.add(new Paragraph("Rsultats des tudiants"));

                Table tableau = new Table(5, resultats_eleves.size());
                tableau.setAutoFillEmptyCells(true);
                tableau.setPadding(2);

                Cell cell = new Cell("Nom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Prnom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("N tudiant");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Note");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage");
                cell.setHeader(true);
                tableau.addCell(cell);

                tableau.endHeaders();
                tableau.setWidth(100);
                fill_data_pdf(tableau);
                document.add(tableau);
            } catch (DocumentException | IOException de) {
                de.printStackTrace();
            }
            document.close();
        }
    } else if (onglet_actif.equals("eleves_pas_num")) {

        if (pdf_file != null) {
            Document document = new Document(PageSize.A4);
            try {
                PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
                document.open();
                document.add(new Paragraph("Rsultats des tudiants"));

                Table tableau = new Table(4, resultats_eleves.size());
                tableau.setAutoFillEmptyCells(true);
                tableau.setPadding(2);

                Cell cell = new Cell("Nom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Prnom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Note");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage");
                cell.setHeader(true);
                tableau.addCell(cell);

                tableau.endHeaders();
                tableau.setWidth(100);
                fill_data_pdf(tableau);
                document.add(tableau);
            } catch (DocumentException | IOException de) {
                de.printStackTrace();
            }
            document.close();
        }
    }

    close_window();
}

From source file:org.activityinfo.server.report.renderer.itext.ItextMapRenderer.java

License:Open Source License

private void renderLegend(MapReportElement element, Document doc) throws DocumentException, IOException {

    Table table = new Table(2);
    table.setBorderWidth(1);/*from   w w  w.j  av a  2 s.  com*/
    table.setWidth(100f);
    table.setBorderColor(new Color(100, 100, 100));
    table.setPadding(5);
    table.setSpacing(0);
    table.setCellsFitPage(true);
    table.setTableFitsPage(true);
    table.setWidths(new int[] { 1, 3 });

    Cell cell = new Cell(I18N.CONSTANTS.legend());
    cell.setHeader(true);
    cell.setColspan(2);
    table.addCell(cell);
    table.endHeaders();

    for (MapLayerLegend legend : element.getContent().getLegends()) {

        Cell symbolCell = new Cell();
        symbolCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        symbolCell.setVerticalAlignment(Element.ALIGN_MIDDLE);

        Image symbol = createLegendSymbol(legend, imageCreator);
        symbolCell.addElement(symbol);

        Cell descriptionCell = new Cell();
        addLegendDescription(element, legend.getDefinition(), descriptionCell);

        table.addCell(symbolCell);
        table.addCell(descriptionCell);
    }
    doc.add(table);
}

From source file:org.activityinfo.server.report.renderer.itext.ItextPivotTableRenderer.java

License:Open Source License

@Override
public void render(DocWriter writer, Document document, PivotTableReportElement element)
        throws DocumentException {

    document.add(ThemeHelper.elementTitle(element.getTitle()));
    ItextRendererHelper.addFilterDescription(document, element.getContent().getFilterDescriptions());
    ItextRendererHelper.addDateFilterDescription(document, element.getFilter().getDateRange());
    PivotTableData data = element.getContent().getData();

    if (data.isEmpty()) {
        document.add(new Paragraph("Aucune Donnes")); // TODO: i18n

    } else {/*from   w w  w  .j  a  va 2  s  . c  o  m*/
        int colDepth = data.getRootColumn().getDepth();
        List<PivotTableData.Axis> colLeaves = data.getRootColumn().getLeaves();
        int colBreadth = colLeaves.size();

        Table table = new Table(colBreadth + 1, 1);
        table.setUseVariableBorders(true);
        table.setWidth(100.0f);
        table.setWidths(calcColumnWidths(document, data, colLeaves));
        table.setBorderWidth(0);

        // first write the column headers

        for (int depth = 1; depth <= colDepth; ++depth) {

            if (depth == 1) {
                Cell cell = ThemeHelper.cornerCell();
                cell.setRowspan(colDepth);
                table.addCell(cell);
            }

            List<PivotTableData.Axis> columns = data.getRootColumn().getDescendantsAtDepth(depth);
            for (PivotTableData.Axis column : columns) {
                Cell cell = ThemeHelper.columnHeaderCell(column.getLabel(), column.isLeaf());
                cell.setColspan(Math.max(1, column.getLeaves().size()));
                table.addCell(cell);
            }

        }
        table.endHeaders();

        for (PivotTableData.Axis row : data.getRootRow().getChildren()) {
            writeRow(table, row, colLeaves, 0);
        }
        document.add(table);
    }
}