List of usage examples for com.lowagie.text Document open
boolean open
To view the source code for com.lowagie.text Document open.
Click Source Link
From source file:com.geek.tutorial.itext.table.SimplePDFTable.java
License:Open Source License
public SimplePDFTable() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("SimplePDFTable.pdf")); document.open(); PdfPTable table = new PdfPTable(2); table.addCell("1"); table.addCell("2"); table.addCell("3"); table.addCell("4"); table.addCell("5"); table.addCell("6"); document.add(table);/*from w w w .j a v a 2s. co m*/ document.close(); }
From source file:com.geek.tutorial.itext.table.SimplePDFTableAlignAndWidth.java
License:Open Source License
public SimplePDFTableAlignAndWidth() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("SimplePDFTableAlignAndWidth.pdf")); document.open(); float[] colsWidth = { 1f, 2f }; // Code 1 PdfPTable table = new PdfPTable(colsWidth); table.setWidthPercentage(90); // Code 2 table.setHorizontalAlignment(Element.ALIGN_LEFT); // Code 3 table.addCell("1"); table.addCell("2"); table.addCell("3"); table.addCell("4"); table.addCell("5"); table.addCell("6"); document.add(table);/*from w ww .j a v a 2s . c om*/ document.close(); }
From source file:com.geek.tutorial.itext.table.SimplePDFTableColspan.java
License:Open Source License
public SimplePDFTableColspan() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("SimplePDFTableColspan.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("column span 2")); cell.setColspan(2);//from w w w .ja va 2 s. c o m table.addCell(cell); table.addCell("1"); table.addCell("2"); table.addCell("3"); table.addCell("4"); table.addCell("5"); table.addCell("6"); document.add(table); document.close(); }
From source file:com.geek.tutorial.itext.text.Chunk_Example.java
License:Open Source License
public Chunk_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("chunk_example.pdf")); document.open(); Font font = new Font(Font.COURIER, 10, Font.BOLD); // 1 font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element", font); // 2 chunk.setBackground(new Color(0xff, 0xe4, 0x00)); // 3 document.add(chunk); // 4 document.close();//from www. j a v a 2 s .c om }
From source file:com.geek.tutorial.itext.text.Paragraph_Example.java
License:Open Source License
public Paragraph_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("paragraph_example.pdf")); document.open(); Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); for (int i = 0; i < 10; i++) { phrase.add(chunk);//from w w w. j a v a 2 s . c om } Paragraph paragraph = new Paragraph(); // 1 paragraph.add(phrase); // 2 document.add(paragraph); // 3 document.add(paragraph); // 4 document.close(); }
From source file:com.geek.tutorial.itext.text.Phrase_Example.java
License:Open Source License
public Phrase_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("phrase_example.pdf")); document.open(); Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); // 1 for (int i = 0; i < 10; i++) { phrase.add(chunk); // 2 }/*from w w w . ja va2s . c o m*/ document.add(phrase); // 3 document.close(); }
From source file:com.globalsight.everest.webapp.pagehandler.edit.inctxrv.pdf.PreviewPDFHelper.java
License:Apache License
public static File setCopyOnlyPermission(File p_file) throws DocumentException, IOException { PdfReader reader = new PdfReader(p_file.getAbsolutePath()); String outPutFile = FileUtils.getPrefix(p_file.getAbsolutePath()) + "_hidebars.pdf"; int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.height(); float height = psize.width(); Document document = new Document(new Rectangle(width, height)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(outPutFile)); writer.setEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); try {/*ww w .j a va 2 s .c o m*/ document.open(); int i = 0; while (i < n) { document.newPage(); i++; PdfImportedPage page1 = writer.getImportedPage(reader, i); writer.addPage(page1); } document.close(); } catch (IllegalArgumentException e) { if (!e.getMessage().equals("PdfReader not opened with owner password")) { throw new EnvoyServletException(e); } else { LOGGER.error(e.getMessage(), e); } } return new File(outPutFile); }
From source file:com.globalsight.everest.webapp.pagehandler.edit.online.PreviewPDFPageHandler.java
License:Apache License
public static File setCopyOnlyPermission(File p_file) throws DocumentException, IOException { PdfReader reader = new PdfReader(p_file.getAbsolutePath()); String outPutFile = FileUtils.getPrefix(p_file.getAbsolutePath()) + "_hidebars.pdf"; int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.height(); float height = psize.width(); Document document = new Document(new Rectangle(width, height)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(outPutFile)); writer.setEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); try {//from w w w. j av a 2 s.c o m document.open(); int i = 0; while (i < n) { document.newPage(); i++; PdfImportedPage page1 = writer.getImportedPage(reader, i); writer.addPage(page1); } document.close(); } catch (IllegalArgumentException e) { if (!e.getMessage().equals("PdfReader not opened with owner password")) { throw new EnvoyServletException(e); } else { CATEGORY.error(e.getMessage(), e); } } return new File(outPutFile); }
From source file:com.googlecode.openmpis.action.AbductorAction.java
License:Open Source License
/** * Prints the abductor's poster in PDF file. * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception/*from www .j ava2s .c om*/ */ public ActionForward printPoster(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Set the paper size and margins Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Retrieve the abductor try { int id = Integer.parseInt(request.getParameter("id")); Abductor abductor = abductorService.getAbductorById(id); // Process the photo String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + "photo" + File.separator + "unknown.png"; if (abductor.getPhoto() != null) { String tokens[] = abductor.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; } // Add some meta information to the document document.addTitle("Poster"); document.addAuthor("OpenMPIS"); document.addSubject("Poster for " + abductor.getNickname()); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Open the document for writing document.open(); // Add the banner Paragraph wantedParagraph = new Paragraph("W A N T E D", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); wantedParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(wantedParagraph); // Add name Paragraph redParagraph; if (!abductor.getNickname().isEmpty()) { redParagraph = new Paragraph( abductor.getFirstName() + " \"" + abductor.getNickname() + "\" " + abductor.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } else { redParagraph = new Paragraph(abductor.getFirstName() + " " + abductor.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); // Add the photo Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(200, 300); image.setAlignment(Image.ALIGN_CENTER); document.add(image); // Add birth date Paragraph blackParagraph; if (abductor.getBirthMonth() > 0) { blackParagraph = new Paragraph( getResources(request).getMessage("label.date.birth") + ": " + getResources(request).getMessage("month." + abductor.getBirthMonth()) + " " + abductor.getBirthDay() + ", " + abductor.getBirthYear(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); } // Add birth place blackParagraph = new Paragraph( getResources(request).getMessage("label.address.city") + ": " + abductor.getCity(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add sex blackParagraph = new Paragraph( getResources(request).getMessage("label.sex") + ": " + getResources(request).getMessage("sex." + abductor.getSex()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add height blackParagraph = new Paragraph( getResources(request).getMessage("label.height") + ": " + abductor.getFeet() + "' " + abductor.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add weight blackParagraph = new Paragraph( getResources(request).getMessage("label.weight") + ": " + abductor.getWeight() + " " + getResources(request).getMessage("label.weight.lbs"), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add hair color blackParagraph = new Paragraph( getResources(request).getMessage("label.color.hair") + ": " + getResources(request).getMessage("color.hair." + abductor.getHairColor()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add eye color blackParagraph = new Paragraph( getResources(request).getMessage("label.color.eye") + ": " + getResources(request).getMessage("color.eye." + abductor.getEyeColor()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add race blackParagraph = new Paragraph( getResources(request).getMessage("label.race") + ": " + getResources(request).getMessage("race." + abductor.getRace()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add circumstance blackParagraph = new Paragraph( getResources(request).getMessage("label.remarks") + ": " + abductor.getRemarks(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add line blackParagraph = new Paragraph("---------------------------------------"); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add contact blackParagraph = new Paragraph(getResources(request).getMessage("global.contact"), FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Poster.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; } catch (NumberFormatException nfe) { return mapping.findForward(Constants.LIST_PERSON); } catch (NullPointerException npe) { return mapping.findForward(Constants.LIST_PERSON); } }
From source file:com.googlecode.openmpis.action.CaseAction.java
License:Open Source License
/** * Writes the cases to a PDF file./*w w w. j a va2 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; }