List of usage examples for com.lowagie.text FontFactory HELVETICA_BOLD
String HELVETICA_BOLD
To view the source code for com.lowagie.text FontFactory HELVETICA_BOLD.
Click Source Link
From source file:displayStructureAsPDFTable.java
License:Open Source License
private void addTitle(IAtomContainer mol, Phrase phrase) { if (mol.getProperty(CDKConstants.TITLE) == null || mol.getProperty(CDKConstants.TITLE).toString().trim().length() == 0) return;//from w ww . j a v a2 s . c o m phrase.add(new Chunk(CDKConstants.TITLE + ": ", FontFactory.getFont(FontFactory.HELVETICA_BOLD))); phrase.add( new Chunk(mol.getProperty(CDKConstants.TITLE) + "\n", FontFactory.getFont(FontFactory.HELVETICA))); }
From source file:displayStructureAsPDFTable.java
License:Open Source License
private void addProperty(Object propertyLabel, IAtomContainer mol, Phrase phrase) { if (mol.getProperty(propertyLabel) == null || mol.getProperty(propertyLabel).toString().trim().length() == 0) return;/* ww w . j a v a2 s .c o m*/ phrase.add(new Chunk(propertyLabel + ": ", FontFactory.getFont(FontFactory.HELVETICA_BOLD))); String value; try { double tmp = Double.parseDouble(mol.getProperty(propertyLabel).toString()); value = decimalFormat.format(tmp); } catch (NumberFormatException nfe) { value = mol.getProperty(propertyLabel).toString(); } phrase.add(new Chunk(value + "\n", FontFactory.getFont(FontFactory.HELVETICA))); }
From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc, boolean whiteBackground) throws Exception { final int margin = 15; File f = File.createTempFile("cages__", ".pdf"); Document doc = new Document(PageSize.A4.rotate()); Image maleImg, femaleImg, nosexImg; try {//from w ww . ja va2s . c o m maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png")); femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png")); nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png")); } catch (Exception e) { throw new Exception("Could not find images in the classpath: " + e); } FileOutputStream os = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(doc, os); doc.open(); PdfContentByte canvas = writer.getDirectContentUnder(); float tileW = (doc.getPageSize().getWidth()) / 4; float tileH = (doc.getPageSize().getHeight()) / 2; for (int i = 0; i < cages.size(); i++) { Container cage = cages.get(i); Study study = cage.getStudy(); Set<Group> groups = cage.getGroups(); Group group = cage.getGroup(); Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME); animals.addAll(cage.getBiosamples()); //Find the treatments applied to this group Set<NamedTreatment> allTreatments = new LinkedHashSet<>(); for (Group gr : groups) { allTreatments.addAll(gr.getAllTreatments(-1)); } //Draw if (i % 8 == 0) { if (i > 0) doc.newPage(); drawCageSeparation(doc, canvas); } int col = (i % 8) % 4; int row = (i % 8) / 4; float x = margin + tileW * col; float x2 = x + tileW - margin; float baseY = tileH * row; float y; //Display Sex canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50)); Image img = null; String sex = getMetadata(animals, "Sex"); if (study.isBlindAll()) { img = nosexImg; } else if (sex.equals("M")) { img = maleImg; } else if (sex.equals("F")) { img = femaleImg; } else if (sex.length() > 0) { img = nosexImg; } if (img != null) { img.scaleToFit(20, 20); img.setAbsolutePosition(tileW * (col + 1) - 33, doc.getPageSize().getHeight() - (tileH * row + 12 + margin)); doc.add(img); } if (group != null && group.getColor() != null && (study != null && !study.isBlind()) && !whiteBackground) { Color c = group.getColor(); canvas.saveState(); canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170); canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2, tileH - 2); canvas.fill(); canvas.restoreState(); } Color treatmentColor = Color.BLACK; if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) { int offset = 0; for (NamedTreatment t : allTreatments) { if (t.getColor() != null) { if (allTreatments.size() == 1) treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2, t.getColor().getBlue() / 2); canvas.saveState(); canvas.setColorStroke(Color.BLACK); canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue()); y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28; canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4, 22, 22); canvas.fillStroke(); canvas.restoreState(); offset++; } } } canvas.beginText(); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f); canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x, doc.getPageSize().getHeight() - (baseY + 23), 0); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f); y = 42 + baseY; canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0); y += 15; canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0); y += 86; canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0); y += 22; canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0); y += 14; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0); y += 23; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0); y += 50; canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0); canvas.endText(); y = 42 + baseY; print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65, doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f); y += 15; if (animals.size() <= 6) { int n = 0; for (Biosample animal : animals) { print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50, 12, 12, FontFactory.HELVETICA, Color.BLACK, 11f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60, doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 11f); } n++; } } else { int nPerRow = animals.size() / 2; int n = 0; for (Biosample animal : animals) { int nx = n / nPerRow; int ny = n % nPerRow; print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA, Color.BLACK, 10f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f); } n++; } } y += 86; print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 22; print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 14; if (!study.isBlind() && printGroupsTreatments) print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 23; if (!study.isBlind() && printGroupsTreatments) print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y, x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor, printTreatmentDesc ? 9f : 10f); y += 50; print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2, 15, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2, 20, 10, FontFactory.HELVETICA, Color.BLACK, 10f); } doc.close(); os.close(); Desktop.getDesktop().open(f); try { Thread.sleep(500); } catch (Exception e) { } }
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// w w w . java2 s . co m */ public ActionForward printPoster(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Set the paper size and margins Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Retrieve the abductor try { int id = Integer.parseInt(request.getParameter("id")); Abductor abductor = abductorService.getAbductorById(id); // Process the photo String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + "photo" + File.separator + "unknown.png"; if (abductor.getPhoto() != null) { String tokens[] = abductor.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; } // Add some meta information to the document document.addTitle("Poster"); document.addAuthor("OpenMPIS"); document.addSubject("Poster for " + abductor.getNickname()); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Open the document for writing document.open(); // Add the banner Paragraph wantedParagraph = new Paragraph("W A N T E D", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); wantedParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(wantedParagraph); // Add name Paragraph redParagraph; if (!abductor.getNickname().isEmpty()) { redParagraph = new Paragraph( abductor.getFirstName() + " \"" + abductor.getNickname() + "\" " + abductor.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } else { redParagraph = new Paragraph(abductor.getFirstName() + " " + abductor.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); // Add the photo Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(200, 300); image.setAlignment(Image.ALIGN_CENTER); document.add(image); // Add birth date Paragraph blackParagraph; if (abductor.getBirthMonth() > 0) { blackParagraph = new Paragraph( getResources(request).getMessage("label.date.birth") + ": " + getResources(request).getMessage("month." + abductor.getBirthMonth()) + " " + abductor.getBirthDay() + ", " + abductor.getBirthYear(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); } // Add birth place blackParagraph = new Paragraph( getResources(request).getMessage("label.address.city") + ": " + abductor.getCity(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add sex blackParagraph = new Paragraph( getResources(request).getMessage("label.sex") + ": " + getResources(request).getMessage("sex." + abductor.getSex()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add height blackParagraph = new Paragraph( getResources(request).getMessage("label.height") + ": " + abductor.getFeet() + "' " + abductor.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add weight blackParagraph = new Paragraph( getResources(request).getMessage("label.weight") + ": " + abductor.getWeight() + " " + getResources(request).getMessage("label.weight.lbs"), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add hair color blackParagraph = new Paragraph( getResources(request).getMessage("label.color.hair") + ": " + getResources(request).getMessage("color.hair." + abductor.getHairColor()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add eye color blackParagraph = new Paragraph( getResources(request).getMessage("label.color.eye") + ": " + getResources(request).getMessage("color.eye." + abductor.getEyeColor()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add race blackParagraph = new Paragraph( getResources(request).getMessage("label.race") + ": " + getResources(request).getMessage("race." + abductor.getRace()), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add circumstance blackParagraph = new Paragraph( getResources(request).getMessage("label.remarks") + ": " + abductor.getRemarks(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add line blackParagraph = new Paragraph("---------------------------------------"); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add contact blackParagraph = new Paragraph(getResources(request).getMessage("global.contact"), FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Poster.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; } catch (NumberFormatException nfe) { return mapping.findForward(Constants.LIST_PERSON); } catch (NullPointerException npe) { return mapping.findForward(Constants.LIST_PERSON); } }
From source file:com.googlecode.openmpis.action.PersonAction.java
License:Open Source License
/** * Prints the person's poster in PDF file. * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception/*w w w . j a v a 2s. co m*/ */ public ActionForward printPoster(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Set the paper size and margins Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Retrieve the person try { int id = Integer.parseInt(request.getParameter("id")); Person person = (Person) personService.getPersonById(id); // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; // Add some meta information to the document document.addTitle("Poster"); document.addAuthor("OpenMPIS"); document.addSubject("Poster for " + person.getNickname()); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Open the document for writing document.open(); // Add the banner if (person.getType() > 4) { Paragraph foundParagraph = new Paragraph("F O U N D", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); foundParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(foundParagraph); } else { Paragraph missingParagraph = new Paragraph("M I S S I N G", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); missingParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(missingParagraph); } // Add date missing or found Paragraph blackParagraph = new Paragraph( getResources(request).getMessage("month." + person.getMonthMissingOrFound()) + " " + person.getDayMissingOrFound() + ", " + person.getYearMissingOrFound(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add missing from location if (person.getType() < 5) { blackParagraph = new Paragraph(person.getMissingFromCity() + ", " + person.getMissingFromProvince(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); } // Add name Paragraph redParagraph; if (!person.getNickname().isEmpty()) { redParagraph = new Paragraph( person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } else { redParagraph = new Paragraph(person.getFirstName() + " " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); // Add the photo Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(200, 300); image.setAlignment(Image.ALIGN_CENTER); document.add(image); // Add description redParagraph = new Paragraph("Description", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); float[] widths = { 0.5f, 0.5f }; PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); if (person.getType() < 5) { pdfptable .addCell( new Phrase( getResources(request).getMessage("label.date.birth") + ": " + getResources(request) .getMessage("month." + person.getBirthMonth()) + " " + person.getBirthDay() + ", " + person.getBirthYear(), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell( new Phrase(getResources(request).getMessage("label.address.city") + ": " + person.getCity(), FontFactory.getFont(FontFactory.HELVETICA, 12))); } pdfptable.addCell(new Phrase( getResources(request).getMessage("label.sex") + ": " + getResources(request).getMessage("sex." + person.getSex()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell( new Phrase( getResources(request).getMessage("label.color.hair") + ": " + getResources(request) .getMessage("color.hair." + person.getHairColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.height") + ": " + person.getFeet() + "' " + person.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.color.eye") + ": " + getResources(request).getMessage("color.eye." + person.getEyeColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.weight") + ": " + person.getWeight() + " " + getResources(request).getMessage("label.weight.lbs"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.race") + ": " + getResources(request).getMessage("race." + person.getRace()), FontFactory.getFont(FontFactory.HELVETICA, 12))); document.add(pdfptable); // Add circumstance redParagraph = new Paragraph(getResources(request).getMessage("label.circumstance"), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); blackParagraph = new Paragraph(person.getCircumstance(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL)); blackParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED); document.add(blackParagraph); // Add line blackParagraph = new Paragraph( "------------------------------------------------------------------------------"); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add contact blackParagraph = new Paragraph(getResources(request).getMessage("global.contact"), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)); blackParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED); document.add(blackParagraph); document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Poster.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; } catch (NumberFormatException nfe) { return mapping.findForward(Constants.LIST_PERSON); } catch (NullPointerException npe) { return mapping.findForward(Constants.LIST_PERSON); } }
From source file:com.googlecode.openmpis.action.ReportAction.java
License:Open Source License
/** * Prints the reports.//from ww w . j a va 2 s. c om * This is the print report action called from the Struts framework. * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception */ public ActionForward printReport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User currentUser = null; // Check if there exists a session if (request.getSession().getAttribute("currentuser") == null) { return mapping.findForward(Constants.EXPIRED); } else { currentUser = (User) request.getSession().getAttribute("currentuser"); } // Check if current user is authorized if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) { // Retrieve person ID try { int personId = Integer.parseInt(request.getParameter("personid")); Person person = personService.getPersonById(personId); // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; // Set the paper size and margins Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Add some meta information to the document document.addTitle("Progress Report"); document.addAuthor("OpenMPIS"); document.addSubject("Progress Report"); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Set the header String date = simpleDateFormat.format(System.currentTimeMillis()); document.setHeader(new HeaderFooter(new Phrase("Report for " + person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName() + " as of " + date), false)); // Set the footer HeaderFooter footer = new HeaderFooter(new Phrase("Page : "), true); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); // Open the document for writing document.open(); // Print the information on person // Add the banner if (person.getType() > 4) { Paragraph foundParagraph = new Paragraph("F O U N D", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); foundParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(foundParagraph); } else { Paragraph missingParagraph = new Paragraph("M I S S I N G", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); missingParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(missingParagraph); } // Add date missing or found Paragraph blackParagraph = new Paragraph( getResources(request).getMessage("month." + person.getMonthMissingOrFound()) + " " + person.getDayMissingOrFound() + ", " + person.getYearMissingOrFound(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add missing from location if (person.getType() < 5) { blackParagraph = new Paragraph( person.getMissingFromCity() + ", " + person.getMissingFromProvince(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); } // Add name Paragraph redParagraph; if (!person.getNickname().isEmpty()) { redParagraph = new Paragraph( person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } else { redParagraph = new Paragraph(person.getFirstName() + " " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); // Add the photo Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(200, 300); image.setAlignment(Image.ALIGN_CENTER); document.add(image); // Add description redParagraph = new Paragraph("Description", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); float[] widths = { 0.5f, 0.5f }; PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); if (person.getType() < 5) { pdfptable .addCell( new Phrase( getResources(request).getMessage("label.date.birth") + ": " + getResources(request) .getMessage("month." + person.getBirthMonth()) + " " + person.getBirthDay() + ", " + person.getBirthYear(), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.address.city") + ": " + person.getCity(), FontFactory.getFont(FontFactory.HELVETICA, 12))); } pdfptable.addCell(new Phrase( getResources(request).getMessage("label.sex") + ": " + getResources(request).getMessage("sex." + person.getSex()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell( new Phrase( getResources(request).getMessage("label.color.hair") + ": " + getResources(request) .getMessage("color.hair." + person.getHairColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell(new Phrase( getResources(request).getMessage("label.height") + ": " + person.getFeet() + "' " + person.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell( new Phrase( getResources(request).getMessage("label.color.eye") + ": " + getResources(request) .getMessage("color.eye." + person.getEyeColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.weight") + ": " + person.getWeight() + " " + getResources(request).getMessage("label.weight.lbs"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.race") + ": " + getResources(request).getMessage("race." + person.getRace()), FontFactory.getFont(FontFactory.HELVETICA, 12))); document.add(pdfptable); // Print information on relative Relative relative = relativeService.getRelativeById(person.getRelativeId()); document.newPage(); document.add(new Paragraph(getResources(request).getMessage("label.relative.name") + ": " + relative.getFirstName() + " " + relative.getLastName())); document.add(new Paragraph(getResources(request).getMessage("label.relation") + ": " + getResources(request).getMessage("relation." + person.getRelationToRelative()))); document.add(new Paragraph(getResources(request).getMessage("label.address") + ": " + relative.getStreet() + ", " + relative.getCity() + ", " + relative.getProvince())); document.add(new Paragraph( getResources(request).getMessage("label.number") + ": " + relative.getNumber())); document.add(new Paragraph( getResources(request).getMessage("label.email") + ": " + relative.getEmail())); // Print information on abductor if (person.getAbductorId() != null) { Abductor abductor = abductorService.getAbductorById(person.getAbductorId()); document.newPage(); document.add(new Paragraph(getResources(request).getMessage("label.abductor.name") + ": " + abductor.getFirstName() + " " + abductor.getLastName())); } // Print sightings if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) { document.setHeader(new HeaderFooter(new Phrase("List of sightings as of " + date), false)); document.newPage(); float sightingsWidths[] = { 0.1f, 0.1f, 0.1f, 0.3f, 0.1f, 0.1f, 0.1f, 0.1f }; pdfptable = new PdfPTable(sightingsWidths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.id"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.date.sent"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.subject"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.message"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.lastname"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.firstname"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.email"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.ipaddress"), FontFactory.getFont(FontFactory.HELVETICA, 12))); List<Message> sightingList = messageService.listAllSightingsForPerson(personId); for (Message sighting : sightingList) { pdfptable.addCell( new Phrase("" + sighting.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getSubject(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getMessage(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getIpAddress(), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); } // Print progress reports if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) { document.setHeader( new HeaderFooter(new Phrase("List of progress reports as of " + date), false)); document.newPage(); float reportsWidths[] = { 0.1f, 0.1f, 0.3f }; pdfptable = new PdfPTable(reportsWidths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.id"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.date.reported"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.report"), FontFactory.getFont(FontFactory.HELVETICA, 12))); List<Report> reportList = reportService.listAllReportsForPerson(personId); for (Report report : reportList) { pdfptable.addCell( new Phrase("" + report.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(report.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(report.getReport(), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); } document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Report.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; } catch (NumberFormatException nfe) { return mapping.findForward(Constants.LIST_PERSON); } catch (NullPointerException npe) { return mapping.findForward(Constants.LIST_PERSON); } } else { return mapping.findForward(Constants.UNAUTHORIZED); } }
From source file:CPS.Core.TODOLists.PDFExporter.java
License:Open Source License
public PDFExporter() { fontHeadFootItal = FontFactory.getFont(FontFactory.HELVETICA_OBLIQUE, 8); fontHeadFootReg = FontFactory.getFont(FontFactory.HELVETICA, 8); fontTableReg = FontFactory.getFont(FontFactory.HELVETICA, 10); fontTableHead = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 10); // fontTableItal = FontFactory.getFont( FontFactory.HELVETICA_OBLIQUE, 10 ); fontPageHeader = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14); dateValidator = new CPSDateValidator(); }
From source file:datasoul.servicelist.ServiceListExporterDocument.java
License:Open Source License
public void addServicePlan() throws DocumentException { ServiceListTable slt = ServiceListTable.getActiveInstance(); Paragraph p = new Paragraph( java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("SERVICE PLAN"), FontFactory.getFont(FontFactory.HELVETICA, 12)); p.setAlignment(Element.ALIGN_CENTER); document.add(p);/*from ww w .j a v a 2 s .c om*/ p = new Paragraph(slt.getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16)); p.setAlignment(Element.ALIGN_CENTER); document.add(p); Table t = new Table(4); t.setWidths(new int[] { 10, 5, 50, 35 }); t.setPadding(2.0f); t.setWidth(100.0f); t.addCell(createHeaderCell( java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("TIME"))); t.addCell( createHeaderCell(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("MIN"))); t.addCell(createHeaderCell( java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("TITLE"))); t.addCell(createHeaderCell( java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("NOTES"))); for (int i = 0; i < slt.getRowCount(); i++) { ServiceItem si = (ServiceItem) slt.getServiceItem(i); Cell c; // Start time c = new Cell(si.getStartTime()); c.setMaxLines(1); c.setVerticalAlignment(Cell.ALIGN_MIDDLE); c.setHorizontalAlignment(Cell.ALIGN_CENTER); t.addCell(c); // Duration c = new Cell(Integer.toString(si.getDuration())); c.setMaxLines(1); c.setVerticalAlignment(Cell.ALIGN_MIDDLE); c.setHorizontalAlignment(Cell.ALIGN_RIGHT); t.addCell(c); // Title c = new Cell(si.getTitle()); c.setVerticalAlignment(Cell.ALIGN_MIDDLE); t.addCell(c); // Notes c = new Cell(si.getNotes()); c.setVerticalAlignment(Cell.ALIGN_MIDDLE); t.addCell(c); } document.add(t); p = new Paragraph(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("NOTES"), FontFactory.getFont(FontFactory.HELVETICA_BOLD)); document.add(p); p = new Paragraph(slt.getNotes(), FontFactory.getFont(FontFactory.HELVETICA)); p.setIndentationLeft(10.0f); document.add(p); document.newPage(); }
From source file:datasoul.servicelist.ServiceListExporterDocument.java
License:Open Source License
private Cell createHeaderCell(String text) throws BadElementException { Cell c = new Cell(new Chunk(text, FontFactory.getFont(FontFactory.HELVETICA_BOLD))); c.setMaxLines(1);/* w w w . j a v a 2 s . c om*/ c.setHeader(true); c.setVerticalAlignment(Cell.ALIGN_MIDDLE); c.setHorizontalAlignment(Cell.ALIGN_CENTER); return c; }
From source file:datasoul.servicelist.ServiceListExporterDocument.java
License:Open Source License
private void addSongHeader(Song s) throws DocumentException { Paragraph p;// w w w. j a v a 2s .co m p = new Paragraph(s.getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16)); document.add(p); if (!s.getSongAuthor().trim().equals("")) { p = new Paragraph(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("AUTHOR") + ": " + s.getSongAuthor(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)); document.add(p); } if (!s.getCopyright().trim().equals("")) { p = new Paragraph(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("COPYRIGHT") + s.getCopyright(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)); document.add(p); } if (!s.getSongSource().trim().equals("")) { p = new Paragraph(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("SOURCE") + s.getSongSource(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)); document.add(p); } }