List of usage examples for com.lowagie.text Table addCell
public void addCell(String content) throws BadElementException
Cell
to the Table
. 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 a 2 s. com * * @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 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 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:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private Table createOptionsQuestionStatisticsTableHeader(String optionLabel, String optionFrequencyLabel) throws Exception { Table statsTable; Cell cell;/* ww w. j a va 2s. c om*/ statsTable = new Table(7); statsTable.setWidth(94); statsTable.setBorder(0); statsTable.setOffset(5); statsTable.setPadding(2); statsTable.setDefaultCellBorder(0); statsTable.setWidths(new int[] { 4, 2, 1, 1, 1, 1, 1 }); cell = new Cell(new Paragraph(optionLabel, boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); cell = new Cell(new Paragraph(optionFrequencyLabel, boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); cell = new Cell(new Paragraph("20%", boldedFont)); cell.setBorder(Cell.BOTTOM); cell.setHorizontalAlignment(cell.ALIGN_RIGHT); statsTable.addCell(cell); cell = new Cell(new Paragraph("40%", boldedFont)); cell.setBorder(Cell.BOTTOM); cell.setHorizontalAlignment(cell.ALIGN_RIGHT); statsTable.addCell(cell); cell = new Cell(new Paragraph("60%", boldedFont)); cell.setBorder(Cell.BOTTOM); cell.setHorizontalAlignment(cell.ALIGN_RIGHT); statsTable.addCell(cell); cell = new Cell(new Paragraph("80%", boldedFont)); cell.setBorder(Cell.BOTTOM); cell.setHorizontalAlignment(cell.ALIGN_RIGHT); statsTable.addCell(cell); cell = new Cell(new Paragraph("100%", boldedFont)); cell.setBorder(Cell.BOTTOM); cell.setHorizontalAlignment(cell.ALIGN_RIGHT); statsTable.addCell(cell); return statsTable; }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeBooleanQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel, String trueLabel, String falseLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel); Cell cell;/*ww w .ja v a 2s .c om*/ Boolean foundOption = false; cell = new Cell(new Paragraph(trueLabel, normalFont)); statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getEntry().equals("1")) { foundOption = true; cell = new Cell( new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); statsTable.addCell(cell); cell = new Cell(); cell.setColspan(5); statsTable.addCell(cell); } foundOption = false; cell = new Cell(new Paragraph(falseLabel, normalFont)); statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getEntry().equals("0")) { foundOption = true; cell = new Cell( new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); statsTable.addCell(cell); cell = new Cell(); cell.setColspan(5); statsTable.addCell(cell); } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeOptionsQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel); Cell cell;/* www.ja v a 2 s. c o m*/ int rowIndex = 0; for (QuestionOption option : question.getOptions()) { Boolean foundOption = false; cell = new Cell(new Paragraph(option.getText(), normalFont)); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (question.getType().getIsMultipleValue()) { //multiple value question (checkboxes) match on order if (questionStatistic.getOptionOrder().equals(option.getOrder())) { foundOption = true; cell = new Cell(new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } else { //single value question match on value if (questionStatistic.getEntry() != null && questionStatistic.getEntry().equals(option.getValue())) { foundOption = true; cell = new Cell(new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} statsTable.addCell(cell); cell = new Cell(); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} statsTable.addCell(cell); cell = new Cell(); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} cell.setColspan(5); statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeBooleanMatrixQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String trueLabel, String falseLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable; Cell cell;/*w ww . ja v a2s. c o m*/ statsTable = new Table(question.getColumnLabels().size() + 1); statsTable.setWidth(94); statsTable.setBorder(0); statsTable.setOffset(5); statsTable.setPadding(2); statsTable.setDefaultCellBorder(0); //header cell = new Cell(); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); } int rowIndex = 1; for (QuestionRowLabel rowLabel : question.getRowLabels()) { cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont)); cell.setBorder(Cell.RIGHT); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { boolean found = false; cell = new Cell(); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder()) && questionStatistic.getEntry().equals("1")) { cell.add(new Paragraph( trueLabel + ": " + percentFormat.format(questionStatistic.getFrequency()), normalFont)); found = true; break; } } if (!found) { cell.add(new Paragraph(trueLabel + ": " + percentFormat.format(0), normalFont)); } found = false; for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder()) && questionStatistic.getEntry().equals("0")) { cell.add(new Paragraph( falseLabel + ": " + percentFormat.format(questionStatistic.getFrequency()), normalFont)); found = true; break; } } if (!found) { cell.add(new Paragraph(falseLabel + ": " + percentFormat.format(0), normalFont)); } statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeNumericMatrixQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String minimumLabel, String maximumLabel, String averageLabel, String standardDeviationLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable; Cell cell;/*w w w .j a va 2 s.c o m*/ statsTable = new Table(question.getColumnLabels().size() + 1); statsTable.setWidth(94); statsTable.setBorder(0); statsTable.setOffset(5); statsTable.setPadding(2); statsTable.setDefaultCellBorder(0); //header cell = new Cell(); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); } int rowIndex = 1; for (QuestionRowLabel rowLabel : question.getRowLabels()) { cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont)); cell.setBorder(Cell.RIGHT); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { boolean found = false; cell = new Cell(); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())) { cell.add(new Paragraph( minimumLabel + ": " + BigDecimalValidator.getInstance() .format(questionStatistic.getMin(), LocaleContextHolder.getLocale()), normalFont)); cell.add(new Paragraph( maximumLabel + ": " + BigDecimalValidator.getInstance() .format(questionStatistic.getMax(), LocaleContextHolder.getLocale()), normalFont)); cell.add(new Paragraph( averageLabel + ": " + BigDecimalValidator.getInstance() .format(questionStatistic.getAverage(), LocaleContextHolder.getLocale()), normalFont)); cell.add(new Paragraph(standardDeviationLabel + ": " + BigDecimalValidator.getInstance().format( questionStatistic.getSampleStandardDeviation(), LocaleContextHolder.getLocale()), normalFont)); break; } } if (!found) { } statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeCurrencyMatrixQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String minimumLabel, String maximumLabel, String averageLabel, String standardDeviationLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable; Cell cell;//from www .j a va 2 s . c om statsTable = new Table(question.getColumnLabels().size() + 1); statsTable.setWidth(94); statsTable.setBorder(0); statsTable.setOffset(5); statsTable.setPadding(2); statsTable.setDefaultCellBorder(0); //header cell = new Cell(); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); } int rowIndex = 1; for (QuestionRowLabel rowLabel : question.getRowLabels()) { cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont)); cell.setBorder(Cell.RIGHT); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { boolean found = false; cell = new Cell(); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())) { cell.add(new Paragraph( minimumLabel + ": " + CurrencyValidator.getInstance() .format(questionStatistic.getMin(), LocaleContextHolder.getLocale()), normalFont)); cell.add(new Paragraph( maximumLabel + ": " + CurrencyValidator.getInstance() .format(questionStatistic.getMax(), LocaleContextHolder.getLocale()), normalFont)); cell.add(new Paragraph( averageLabel + ": " + CurrencyValidator.getInstance() .format(questionStatistic.getAverage(), LocaleContextHolder.getLocale()), normalFont)); cell.add(new Paragraph(standardDeviationLabel + ": " + CurrencyValidator.getInstance().format( questionStatistic.getSampleStandardDeviation(), LocaleContextHolder.getLocale()), normalFont)); break; } } if (!found) { } statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeDateMatrixQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String minimumLabel, String maximumLabel, String dateFormat) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable; Cell cell;//from ww w . j ava2 s . c o m statsTable = new Table(question.getColumnLabels().size() + 1); statsTable.setWidth(94); statsTable.setBorder(0); statsTable.setOffset(5); statsTable.setPadding(2); statsTable.setDefaultCellBorder(0); //header cell = new Cell(); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont)); cell.setBorder(Cell.BOTTOM); statsTable.addCell(cell); } int rowIndex = 1; for (QuestionRowLabel rowLabel : question.getRowLabels()) { cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont)); cell.setBorder(Cell.RIGHT); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } statsTable.addCell(cell); for (QuestionColumnLabel columnLabel : question.getColumnLabels()) { boolean found = false; cell = new Cell(); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(244, 244, 244)); } for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getRowOrder().equals(rowLabel.getOrder()) && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())) { cell.add(new Paragraph(minimumLabel + ": " + DateValidator.getInstance().format(questionStatistic.getMinDate(), dateFormat), normalFont)); cell.add(new Paragraph(maximumLabel + ": " + DateValidator.getInstance().format(questionStatistic.getMaxDate(), dateFormat), normalFont)); break; } } if (!found) { } statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.SurveyPdf.java
License:Open Source License
private void writeAnswersMatrix(Document document, Question question, Boolean[][] answerValuesMatrix, String falseMessage, String trueMessage) throws Exception { Table matrixTable; Cell cell;/*from w w w.ja v a 2 s . co m*/ Paragraph questionParagraph = new Paragraph(); questionParagraph.add(new Chunk(question.getQuestionText().trim() + ": ", boldedFont)); document.add(questionParagraph); matrixTable = new Table(question.getColumnLabels().size() + 1); matrixTable.setPadding(2); matrixTable.setWidth(100); matrixTable.setDefaultCellBorder(0); matrixTable.setBorder(0); matrixTable.setOffset(4); matrixTable.setAutoFillEmptyCells(true); matrixTable.setCellsFitPage(true); matrixTable.setTableFitsPage(true); cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); matrixTable.addCell(cell); for (QuestionColumnLabel questionColumnLabel : question.getColumnLabels()) { cell = new Cell(new Paragraph(questionColumnLabel.getLabel(), boldedFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); matrixTable.addCell(cell); } int rowIndex = 0; for (QuestionRowLabel questionRowLabel : question.getRowLabels()) { int columnIndex = 0; questionParagraph = new Paragraph(questionRowLabel.getLabel(), boldedFont); questionParagraph.setLeading(12, 0); cell = new Cell(questionParagraph); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(231, 238, 244)); } matrixTable.addCell(cell); for (QuestionColumnLabel questionColumnLabel : question.getColumnLabels()) { questionParagraph = new Paragraph( answerValuesMatrix[rowIndex][columnIndex] ? trueMessage : falseMessage, normalFont); questionParagraph.setLeading(12, 0); cell = new Cell(questionParagraph); if ((rowIndex % 2) == 1) { cell.setBackgroundColor(new Color(231, 238, 244)); } matrixTable.addCell(cell); columnIndex++; } rowIndex++; } document.add(matrixTable); }