List of usage examples for com.lowagie.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected void startVisitTableRow(XWPFTableRow row, IITextContainer tableContainer, int rowIndex, boolean headerRow) throws Exception { if (headerRow) { PdfPTable table = (PdfPTable) tableContainer; table.setHeaderRows(table.getHeaderRows() + 1); }/*from w ww. j av a 2 s .c om*/ super.startVisitTableRow(row, tableContainer, rowIndex, headerRow); }
From source file:gov.utah.dts.det.ccl.documents.templating.templates.AbstractCaseloadTemplate.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor) throws TemplateException { Long specialistId = (Long) context.get("specId"); if (specialistId == null) { throw new TemplateException("Specialist id is required."); }//from w ww. j a v a 2s. c o m CaseloadSortBy sortBy = CaseloadSortBy.getDefaultSortBy(); String sortByStr = (String) context.get("sortBy"); if (sortByStr != null) { sortBy = CaseloadSortBy.valueOf(sortByStr); } Person specialist = personService.getPerson(specialistId); context.put(SPECIALIST_KEY, specialist); List<FacilityCaseloadView> caseload = getCaseload(specialistId, sortBy); setFileName(context, descriptor); try { Document document = new Document(PageSize.LETTER.rotate(), MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter.getInstance(document, outputStream); document.open(); document.add(new Paragraph(getReportTitle() + " for " + specialist.getFirstAndLastName(), FONT)); //columns: name, facility id, address, phone, 1st director(s), status, type, capacity (<2) PdfPTable table = new PdfPTable(8); table.setWidths(new float[] { 23f, 25f, 11f, 13f, 5f, 9f, 7f, 7f }); table.setWidthPercentage(100); table.setSpacingBefore(FONT_SIZE); table.getDefaultCell().setPadding(TABLE_CELL_PADDING); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setBorderWidthBottom(.5f); table.setHeaderRows(1); table.addCell(new Phrase("Facility Name", HEADER_FONT)); table.addCell(new Phrase("Address", HEADER_FONT)); table.addCell(new Phrase("Phone", HEADER_FONT)); table.addCell(new Phrase("1st Director(s)", HEADER_FONT)); table.addCell(new Phrase("Type", HEADER_FONT)); table.addCell(new Phrase("Exp Dt", HEADER_FONT)); table.addCell(new Phrase("Adult Cap", HEADER_FONT)); table.addCell(new Phrase("Youth Cap", HEADER_FONT)); boolean hasInProcess = false; for (FacilityCaseloadView fcv : caseload) { if (fcv.getStatus() == FacilityStatus.REGULATED || fcv.getStatus() == FacilityStatus.IN_PROCESS) { StringBuilder name = new StringBuilder(); if (fcv.getStatus() == FacilityStatus.IN_PROCESS) { hasInProcess = true; name.append("* "); } name.append(fcv.getName()); table.addCell(new Phrase(name.toString(), FONT)); table.addCell(new Phrase(fcv.getLocationAddress().toString(), FONT)); table.addCell(new Phrase(fcv.getPrimaryPhone().getFormattedPhoneNumber(), FONT)); table.addCell(new Phrase(fcv.getDirectorNames(), FONT)); String typeAbbrev = null; /* if (fcv.getLicenseType() != null) { typeAbbrev = applicationService.getApplicationPropertyValue("facility.license.type." + fcv.getLicenseType().getId()+ ".abbrev"); } */ table.addCell(new Phrase(typeAbbrev != null ? typeAbbrev : "", FONT)); // table.addCell(new Phrase(fcv.getExpirationDate() != null ? DATE_FORMATTER.format(fcv.getExpirationDate()) : "", FONT)); table.addCell(new Phrase("", FONT)); // if (fcv.getAdultTotalSlots() == null) { table.addCell(new Phrase("")); // } else { // table.addCell(new Phrase(fcv.getAdultTotalSlots().toString(), FONT)); // } // if (fcv.getYouthTotalSlots() == null) { table.addCell(new Phrase("")); // } else { // table.addCell(new Phrase(fcv.getYouthTotalSlots().toString(), FONT)); // } } } document.add(table); if (hasInProcess) { document.add(new Paragraph( "* - Facility is in the process of becoming a regulated child care facility.", FONT)); } document.close(); } catch (DocumentException de) { throw new TemplateException(de); } }
From source file:ispyb.common.util.export.PdfExporterSample.java
License:Open Source License
/** * Exports the file for viewSample for shipment * //from w w w.java 2 s .c o m * @return * @throws Exception */ public ByteArrayOutputStream exportAsPdf() throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); document.addTitle("exportSamplesView"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); HeaderFooter header; // header + footer if (viewName != null) header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc + " --- " + viewName), false); else header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc), false); header.setAlignment(Element.ALIGN_CENTER); header.setBorderWidth(1); header.getBefore().getFont().setSize(8); HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorderWidth(1); footer.getBefore().getFont().setSize(6); document.setHeader(header); document.setFooter(footer); document.open(); if (aList.isEmpty()) { document.add(new Paragraph("There is no samples in this report")); document.close(); return baos; } // Create first table for samples int NumColumns = 19; PdfPTable table = new PdfPTable(NumColumns); int headerwidths[] = { 6, 6, 6, 6, 6, 4, 6, 4, 4, 4, 4, 4, 4, 8, 5, 5, 5, 10, 6 }; // percentage table.setWidths(headerwidths); table.setWidthPercentage(100); // percentage table.getDefaultCell().setPadding(3); table.getDefaultCell().setBorderWidth(1); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // header PdfPCell cell = new PdfPCell(); table.addCell(new Paragraph("Protein", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Sample name", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Smp code", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Dewar", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Container", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Loc. in cont.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Space group", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell a", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell b", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell c", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell alpha", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell beta", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell gamma", new Font(Font.HELVETICA, 8))); cell = new PdfPCell(new Paragraph("Crystal comments", new Font(Font.HELVETICA, 8))); table.addCell(cell); table.addCell(new Paragraph("Already observed resol.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Required resol.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Min. resol.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Sample comments", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Sample status", new Font(Font.HELVETICA, 8))); table.setHeaderRows(1); // this is the end of the table header table.getDefaultCell().setBorderWidth(1); DecimalFormat df1 = new DecimalFormat("#####0.0"); DecimalFormat df2 = new DecimalFormat("#####0.00"); Iterator it = aList.iterator(); int i = 1; String currentContainer = "next"; String nextContainer = "next"; while (it.hasNext()) { table.getDefaultCell().setGrayFill(0.99f); if (i % 2 == 1) { table.getDefaultCell().setGrayFill(0.9f); } BLSample3VO samplefv = (BLSample3VO) it.next(); LOG.debug("table of datacollections pdf " + samplefv.getBlSampleId()); if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) nextContainer = samplefv.getContainerVO().getCode(); else nextContainer = "next"; // in the case of view sorted by dewar/container, we add a page break afetr each container if (sortView.equals("2") && !currentContainer.equals(nextContainer)) { document.add(table); table.deleteBodyRows(); document.newPage(); } if (samplefv.getCrystalVO().getProteinVO().getAcronym() != null) table.addCell(new Paragraph(samplefv.getCrystalVO().getProteinVO().getAcronym(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getName() != null) table.addCell(new Paragraph(samplefv.getName(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCode() != null) table.addCell(new Paragraph(samplefv.getCode(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getDewarVO() != null && samplefv.getContainerVO().getDewarVO().getCode() != null) table.addCell(new Paragraph(samplefv.getContainerVO().getDewarVO().getCode(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) { currentContainer = samplefv.getContainerVO().getCode(); table.addCell(new Paragraph(currentContainer, new Font(Font.HELVETICA, 8))); } else { currentContainer = "current"; table.addCell(""); } if (samplefv.getLocation() != null) table.addCell(new Paragraph(samplefv.getLocation(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getSpaceGroup() != null) table.addCell(new Paragraph(samplefv.getCrystalVO().getSpaceGroup(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellA() != null) table.addCell( new Paragraph(df1.format(samplefv.getCrystalVO().getCellA()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellB() != null) table.addCell( new Paragraph(df1.format(samplefv.getCrystalVO().getCellB()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellC() != null) table.addCell( new Paragraph(df1.format(samplefv.getCrystalVO().getCellC()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellAlpha() != null) table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellAlpha()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellBeta() != null) table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellBeta()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellGamma() != null) table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellGamma()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getComments() != null) table.addCell(new Paragraph(samplefv.getCrystalVO().getComments(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getDiffractionPlanVO() != null && samplefv.getDiffractionPlanVO().getObservedResolution() != null) { table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getObservedResolution()), new Font(Font.HELVETICA, 8))); } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null && samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution() != null) table.addCell(new Paragraph( df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getDiffractionPlanVO() != null && samplefv.getDiffractionPlanVO().getRequiredResolution() != null) { table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getRequiredResolution()), new Font(Font.HELVETICA, 8))); } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null && samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution() != null) table.addCell(new Paragraph( df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getDiffractionPlanVO() != null && samplefv.getDiffractionPlanVO().getMinimalResolution() != null) { table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getMinimalResolution()), new Font(Font.HELVETICA, 8))); } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null && samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution() != null) table.addCell(new Paragraph( df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getComments() != null && samplefv.getComments() != "") table.addCell(new Paragraph(samplefv.getComments(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getBlSampleStatus() != null) table.addCell(new Paragraph(samplefv.getBlSampleStatus(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (i % 2 == 1) { table.getDefaultCell().setGrayFill(0.0f); } i++; } document.add(table); document.close(); return baos; }
From source file:it.eng.spagobi.engines.worksheet.exporter.DataSourceTablePDFExporter.java
License:Mozilla Public License
/** * Builds the header of the table..//from w ww . j a v a2 s .c om * It creates also the object table.. * @param dataStore * @return the table object * @throws BadElementException */ public PdfPTable buildTableHeader(IDataStore dataStore) throws BadElementException { logger.debug("IN: building the headers of the table"); IMetaData dataStoreMetaData = dataStore.getMetaData(); int colunum = dataStoreMetaData.getFieldCount(); List<String> columnsName = new ArrayList<String>(); //reads the names of the visible table columns for (int j = 0; j < colunum; j++) { String fieldName = dataStoreMetaData.getFieldAlias(j); IFieldMetaData fieldMetaData = dataStoreMetaData.getFieldMeta(j); // String format = (String) fieldMetaData.getProperty("format"); String alias = (String) fieldMetaData.getAlias(); if (alias != null && !alias.equals("")) { columnsName.add(alias); } else { columnsName.add(fieldName); } } PdfPTable table = new PdfPTable(colunum); //For each column builds a cell PdfPCell d = table.getDefaultCell(); if (colunum < 4) { table.setWidthPercentage(colunum * 25); } else { table.setWidthPercentage(100); } for (int j = 0; j < colunum; j++) { PdfPCell cell = new PdfPCell(new Phrase(columnsName.get(j))); //cell.setHeader(true); cell.setBorderColor(cellsBorderColor); cell.setBackgroundColor(headerbackgroundColor); table.addCell(cell); } table.setHeaderRows(1); logger.debug("Out: built the headers of the table"); return table; }
From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java
License:Open Source License
private static void createInfospcoopTable(Section subCatPart, Infospcoop infospcoop) throws BadElementException { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Infospcoop")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2);/*from w w w. ja v a2s . c o m*/ table.addCell(c1); table.setHeaderRows(1); //riga 1 table.addCell(new Phrase("IdEgov")); table.addCell(new Phrase(infospcoop.getIdEgov())); // riga 2 table.addCell(new Phrase("Soggetto Erogatore")); table.addCell(new Phrase(infospcoop.getTipoSoggettoErogatore() + "/" + infospcoop.getSoggettoErogatore())); // riga 3 table.addCell(new Phrase("Soggetto Fruitore")); table.addCell(new Phrase(infospcoop.getTipoSoggettoFruitore() + "/" + infospcoop.getSoggettoFruitore())); // riga 4 table.addCell(new Phrase("Servizio")); table.addCell(new Phrase(infospcoop.getTipoServizio() + "/" + infospcoop.getServizio())); // riga 5 table.addCell(new Phrase("Azione")); table.addCell(new Phrase(infospcoop.getAzione())); subCatPart.add(table); }
From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java
License:Open Source License
private static void createEventoTable(Section subCatPart, Evento evento) throws BadElementException { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Evento Id[" + evento.getId() + "]")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2);//from w w w . j a va 2 s .c o m table.addCell(c1); table.setHeaderRows(1); //riga 1 if (evento.getData() != null) { table.addCell(new Phrase("Data registrazione")); table.addCell(new Phrase("" + evento.getData())); } //riga 1 if (evento.getDominio() != null) { table.addCell(new Phrase("Id Dominio")); table.addCell(new Phrase(evento.getDominio())); } //riga 1 if (evento.getIuv() != null) { table.addCell(new Phrase("IUV")); table.addCell(new Phrase(evento.getIuv())); } //riga 1 if (evento.getCcp() != null) { table.addCell(new Phrase("CCP")); table.addCell(new Phrase(evento.getCcp())); } //riga 1 if (evento.getPsp() != null) { table.addCell(new Phrase("Id PSP")); table.addCell(new Phrase(evento.getPsp())); } //riga 1 if (evento.getTipoVersamento() != null) { table.addCell(new Phrase("Tipo Versamento")); table.addCell(new Phrase(evento.getTipoVersamento())); } //riga 1 if (evento.getComponente() != null) { table.addCell(new Phrase("Componente")); table.addCell(new Phrase(evento.getComponente().toString())); } //riga 1 if (evento.getCategoria() != null) { table.addCell(new Phrase("Categoria Evento")); table.addCell(new Phrase(evento.getCategoria().toString())); } //riga 1 if (evento.getTipo() != null) { table.addCell(new Phrase("Tipo Evento")); table.addCell(new Phrase(evento.getTipo())); } //riga 1 if (evento.getSottoTipo() != null) { table.addCell(new Phrase("Sottotipo Evento")); table.addCell(new Phrase(evento.getSottoTipo().toString())); } //riga 1 if (evento.getFruitore() != null) { table.addCell(new Phrase("Id Fruitore")); table.addCell(new Phrase(evento.getFruitore())); } //riga 1 if (evento.getErogatore() != null) { table.addCell(new Phrase("Id Erogatore")); table.addCell(new Phrase(evento.getErogatore())); } //riga 1 if (evento.getStazioneIntermediarioPA() != null) { table.addCell(new Phrase("Id Stazione Intermediario PA")); table.addCell(new Phrase(evento.getStazioneIntermediarioPA())); } //riga 1 if (evento.getCanalePagamento() != null) { table.addCell(new Phrase("Canale Pagamento")); table.addCell(new Phrase(evento.getCanalePagamento())); } //riga 1 if (evento.getParametri() != null) { table.addCell(new Phrase("Parametri Specifici Interfaccia")); table.addCell(new Phrase(evento.getParametri())); } if (evento.getEsito() != null) { table.addCell(new Phrase("Esito")); table.addCell(new Phrase(evento.getEsito())); } subCatPart.add(table); }
From source file:net.bull.javamelody.internal.web.pdf.PdfAbstractTableReport.java
License:Apache License
void initTable(List<String> headers, int[] relativeWidths) throws DocumentException { assert headers.size() == relativeWidths.length; final PdfPTable mytable = new PdfPTable(headers.size()); mytable.setWidthPercentage(100);/*from w ww. ja va2s. c o m*/ mytable.setWidths(relativeWidths); mytable.setHeaderRows(1); final PdfPCell defaultCell = mytable.getDefaultCell(); defaultCell.setGrayFill(0.9f); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); defaultCell.setPaddingLeft(0); defaultCell.setPaddingRight(0); final Font tableHeaderFont = PdfFonts.TABLE_HEADER.getFont(); for (final String header : headers) { mytable.addCell(new Phrase(header, tableHeaderFont)); } defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); this.table = mytable; }
From source file:net.bull.javamelody.internal.web.pdf.PdfRuntimeDependenciesReport.java
License:Apache License
private void writeHeader() throws DocumentException { final List<String> headers = new ArrayList<String>(); headers.add("Beans"); headers.addAll(calledBeans);/*from ww w. j a va 2 s . c om*/ final int[] relativeWidths = new int[headers.size()]; Arrays.fill(relativeWidths, 0, headers.size(), 1); relativeWidths[0] = 4; final PdfPTable table = new PdfPTable(headers.size()); table.setWidthPercentage(100); table.setWidths(relativeWidths); table.setHeaderRows(1); final PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setGrayFill(0.9f); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); defaultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); defaultCell.setPaddingLeft(0); defaultCell.setPaddingRight(0); for (final String header : headers) { table.addCell(new Phrase(header, boldCellFont)); // pas la premire entte de colonne defaultCell.setRotation(90); } defaultCell.setRotation(0); defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); currentTable = table; }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * This Method is for to calculate the overall or gender summary * //from www. ja v a2s .c o m * @param startYear start year to calculate the summary * @param endYear end year to calculate the summary * @param type this is used for to determinate the type the report to create */ private void addBudgetsSummaryByPartners(int startYear, int endYear, int typeSummary) { try { Paragraph cell; if (typeSummary == 0) { cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Overall" }), BODY_TEXT_BOLD_FONT); } else { cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Gender" }), BODY_TEXT_BOLD_FONT); } PdfPTable table; if (project.isCoFundedProject()) { table = new PdfPTable(4); table.setWidths(new int[] { 2, 3, 3, 3 }); } else { table = new PdfPTable(2); table.setWidths(new int[] { 3, 3 }); } table.setLockedWidth(true); table.setTotalWidth(400); table.setHeaderRows(1); // Add cell with the name summary this.addCustomTableCell(table, cell, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); cell = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); if (project.isCoFundedProject()) { if (typeSummary == 0) { cell = new Paragraph( this.getText("summaries.project.budget.overall.text", new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph( this.getText("summaries.project.budget.overall.text", new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } else { cell = new Paragraph( this.getText("summaries.project.budget.overall.gender", new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph( this.getText("summaries.project.budget.overall.gender", new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } this.addTableHeaderCell(table, cell); // Total column cell = new Paragraph(this.getText("summaries.project.budget.overall.total") + " (USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); } else { if (typeSummary == 0) { cell = new Paragraph( this.getText("summaries.project.budget.overall.text", new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } else { cell = new Paragraph( this.getText("summaries.project.budget.overall.gender", new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } this.addTableHeaderCell(table, cell); } double value, valueSum; value = 0.0; for (int year = startYear; year <= endYear; year++) { cell = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 0); valueSum = 0.0; if (project.isCoFundedProject()) { if (typeSummary == 0) { // amount w1/w2 value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(), BudgetType.W1_W2.getValue(), year); cell = new Paragraph(this.budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; // amount w3/Bilateral value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(), BudgetType.W3_BILATERAL.getValue(), year); } else { // gender w1/w2 value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(), BudgetType.W1_W2.getValue(), year); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; // gender w3/Bilateral value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(), BudgetType.W3_BILATERAL.getValue(), year); } cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); // Total valueSum += value; cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } else { if (typeSummary == 0) { // amount w1/w2 value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(), this.getBudgetType().getValue(), year); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } else { // gender w1/w2 value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(), this.getBudgetType().getValue(), year); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } } } // ********************** Totals ************* cell = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 0); if (project.isCoFundedProject()) { if (typeSummary == 0) { value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(), BudgetType.W1_W2.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(), BudgetType.W3_BILATERAL.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum += value; } else { value = budgetManager.calculateTotalGenderPercentageByType(project.getId(), BudgetType.W1_W2.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; value = budgetManager.calculateTotalGenderPercentageByType(project.getId(), BudgetType.W3_BILATERAL.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum += value; } // Total cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } else { if (typeSummary == 0) { value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(), this.getBudgetType().getValue()); } else { value = budgetManager.calculateTotalGenderPercentageByType(project.getId(), this.getBudgetType().getValue()); } cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; } document.add(table); cell = new Paragraph(Chunk.NEWLINE); document.add(cell); } catch (DocumentException e) { LOG.error( "-- generatePdf() > There was an error adding the table with content for case study summary. ", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addProjectCCAFSOutcomes(String number) { PdfPTable table = new PdfPTable(3); Paragraph cell = new Paragraph(); Paragraph indicatorsBlock = new Paragraph(); indicatorsBlock.setAlignment(Element.ALIGN_JUSTIFIED); indicatorsBlock.setKeepTogether(true); Paragraph title = new Paragraph(number + ".2 " + this.getText("summaries.project.indicatorsContribution"), HEADING3_FONT);/*from w ww .j a v a 2 s . c om*/ indicatorsBlock.add(Chunk.NEWLINE); indicatorsBlock.add(title); try { document.add(indicatorsBlock); List<IPElement> listIPElements = this.getMidOutcomesPerIndicators(); if (!listIPElements.isEmpty()) { if (project.isReporting()) { for (IPElement outcome : listIPElements) { Paragraph outcomeBlock = new Paragraph(); int indicatorIndex = 1; outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomeBlock.setFont(BODY_TEXT_BOLD_FONT); outcomeBlock.add(outcome.getProgram().getAcronym()); outcomeBlock.add(" - " + this.getText("summaries.project.midoutcome")); outcomeBlock.setFont(BODY_TEXT_FONT); outcomeBlock.add(outcome.getDescription()); outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.add(Chunk.NEWLINE); document.add(outcomeBlock); for (IPIndicator outcomeIndicator : outcome.getIndicators()) { outcomeIndicator = outcomeIndicator.getParent() != null ? outcomeIndicator.getParent() : outcomeIndicator; List<IPIndicator> indicators = project.getIndicatorsByParent(outcomeIndicator.getId()); if (indicators.isEmpty()) { continue; } Paragraph indicatorDescription = new Paragraph(); indicatorDescription.setFont(BODY_TEXT_BOLD_FONT); indicatorDescription.add(this.getText("summaries.project.indicators")); indicatorDescription.add(String.valueOf(indicatorIndex) + ": "); indicatorDescription.setFont(BODY_TEXT_FONT); indicatorDescription.setAlignment(Element.ALIGN_JUSTIFIED); indicatorDescription.add(outcomeIndicator.getDescription()); document.add(indicatorDescription); document.add(Chunk.NEWLINE); ; PdfPCell cell_new; for (IPIndicator indicator : indicators) { table = new PdfPTable(3); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 3, 3, 3 }); table.setHeaderRows(1); if (indicator.getOutcome().getId() != outcome.getId()) { continue; } cell = new Paragraph(this.messageReturn(String.valueOf(indicator.getYear())), TABLE_HEADER_FONT); cell_new = new PdfPCell(cell); // Set alignment cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND); // Set padding cell_new.setUseBorderPadding(true); cell_new.setPadding(3); // Set border color cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(3); this.addTableHeaderCell(table, cell_new); // Target value cell = new Paragraph(this.getText("summaries.project.indicator.targetValue"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getTarget())); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); // Cumulative target to date // TODO cell = new Paragraph(this.getText("summaries.project.indicator.cumulative"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn( project.calculateAcumulativeTarget(indicator.getYear(), indicator))); if (indicator.getYear() <= this.currentReportingYear) { this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); // achieved cell = new Paragraph(this.getText("summaries.project.indicator.archieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); if (indicator.getArchived() == null) { cell.add(this.messageReturn(null)); } else { cell.add(this.messageReturn(String.valueOf(indicator.getArchived()))); } this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } else { this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 2); } // target narrative cell = new Paragraph(this.getText("summaries.project.indicator.targetNarrative"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getDescription())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); // targets achieved if (indicator.getYear() <= this.currentReportingYear) { cell = new Paragraph( this.getText("summaries.project.indicator.targetsAchieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getNarrativeTargets())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); } // Target gender cell = new Paragraph(this.getText("summaries.project.indicator.targetGender"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getGender())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); // Target achieved gender if (indicator.getYear() <= this.currentReportingYear) { cell = new Paragraph(this.getText("summaries.project.indicator.genderAchieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getNarrativeGender())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); } document.add(table); document.add(Chunk.NEWLINE); } indicatorIndex++; } } //////////// Planning } else { for (IPElement outcome : listIPElements) { Paragraph outcomeBlock = new Paragraph(); int indicatorIndex = 1; outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomeBlock.setFont(BODY_TEXT_BOLD_FONT); outcomeBlock.add(outcome.getProgram().getAcronym()); outcomeBlock.add(" - " + this.getText("summaries.project.midoutcome")); outcomeBlock.setFont(BODY_TEXT_FONT); outcomeBlock.add(outcome.getDescription()); outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.add(Chunk.NEWLINE); document.add(outcomeBlock); for (IPIndicator outcomeIndicator : outcome.getIndicators()) { outcomeIndicator = outcomeIndicator.getParent() != null ? outcomeIndicator.getParent() : outcomeIndicator; List<IPIndicator> indicators = project.getIndicatorsByParent(outcomeIndicator.getId()); if (indicators.isEmpty()) { continue; } Paragraph indicatorDescription = new Paragraph(); indicatorDescription.setFont(BODY_TEXT_BOLD_FONT); indicatorDescription.add(this.getText("summaries.project.indicators")); indicatorDescription.add(String.valueOf(indicatorIndex) + ": "); indicatorDescription.setFont(BODY_TEXT_FONT); indicatorDescription.setAlignment(Element.ALIGN_JUSTIFIED); indicatorDescription.add(outcomeIndicator.getDescription()); document.add(indicatorDescription); document.add(Chunk.NEWLINE); ; table = new PdfPTable(4); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 1, 3, 3, 3 }); table.setHeaderRows(1); // Headers cell = new Paragraph(this.getText("summaries.project.indicator.year"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetValue"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetNarrative"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetGender"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); for (IPIndicator indicator : indicators) { if (indicator.getOutcome().getId() != outcome.getId()) { continue; } cell = new Paragraph(this.messageReturn(String.valueOf(indicator.getYear())), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(this.messageReturn(indicator.getTarget()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(this.messageReturn(indicator.getDescription()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(this.messageReturn(indicator.getGender()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } indicatorIndex++; document.add(table); document.add(Chunk.NEWLINE); } } } // When there isn't elements in indicators } else { cell = new Paragraph(this.getText("summaries.project.empty")); document.add(cell); } } catch ( DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }