List of usage examples for com.lowagie.text.pdf PdfPTable PdfPTable
public PdfPTable(PdfPTable table)
PdfPTable
. From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addProjectContributions() { try {/*from w ww. j a v a 2s .c o m*/ PdfPTable table = new PdfPTable(2); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 7, 3 }); Paragraph cell; StringBuffer projectFocuses = new StringBuffer(); // ************************ Adding flagships and regions ********************************** List<IPProgram> listIPFlagship = project.getFlagships(); List<IPProgram> listIPRegions = project.getRegions(); if (listIPFlagship.isEmpty() && listIPRegions.isEmpty()) { cell = new Paragraph(this.getText("summaries.project.ipContributions"), BODY_TEXT_BOLD_FONT); cell.setFont(BODY_TEXT_BOLD_FONT); cell.add(": "); projectFocuses.append(this.getText("summaries.project.empty")); cell.setFont(BODY_TEXT_FONT); cell.add(projectFocuses.toString()); document.add(cell); document.add(Chunk.NEWLINE); } else { cell = new Paragraph(this.getText("summaries.project.ipContributions"), BODY_TEXT_BOLD_FONT); this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); cell = new Paragraph("", TABLE_HEADER_FONT); cell.setAlignment(Element.ALIGN_LEFT); cell.add(this.getText("summaries.project.ipContributions.flagship")); this.addTableHeaderCell(table, cell); cell = new Paragraph("", TABLE_HEADER_FONT); cell.setAlignment(Element.ALIGN_LEFT); cell.add(this.getText("summaries.project.ipContributions.region")); this.addTableHeaderCell(table, cell); int sizeFlaships = listIPFlagship.size(); int sizeRegions = listIPRegions.size(); if (sizeFlaships < sizeRegions) { this.addEmptyFlashigAndRegion(listIPFlagship, sizeRegions); } else if (sizeFlaships > sizeRegions) { this.addEmptyFlashigAndRegion(listIPRegions, sizeFlaships); } IPProgram program; for (int a = 0; a < listIPRegions.size(); a++) { // Flashing program = listIPFlagship.get(a); if (program.getComposedName() == null || program.getComposedName().isEmpty()) { cell = new Paragraph("", TABLE_BODY_FONT); } else { cell = new Paragraph(program.getComposedName(), TABLE_BODY_FONT); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Regions program = listIPRegions.get(a); if (program.getComposedName() == null || program.getComposedName().isEmpty()) { cell = new Paragraph("", TABLE_BODY_FONT); } else { cell = new Paragraph(program.getComposedName(), TABLE_BODY_FONT); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); } document.add(table); document.add(Chunk.NEWLINE); } // ******************** Adding Bilateral ******************************************** List<Project> listLinkageProject = project.getLinkedProjects(); cell = new Paragraph(); projectFocuses = new StringBuffer(); if (project.isBilateralProject()) { projectFocuses .append(this.getText("summaries.project.ipContributions.project", new String[] { "Core" })); } else { projectFocuses.append( this.getText("summaries.project.ipContributions.project", new String[] { "Bilateral" })); } if (listLinkageProject != null && !listLinkageProject.isEmpty()) { table = new PdfPTable(1); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); cell.setFont(TABLE_HEADER_FONT); cell.add(projectFocuses.toString()); table.setWidths(new int[] { 5 }); // Adding Header this.addTableHeaderCell(table, cell); for (Project projectContribution : project.getLinkedProjects()) { projectFocuses = new StringBuffer(); projectFocuses.append(projectContribution.getId()); projectFocuses.append(" - "); projectFocuses.append(projectContribution.getTitle()); cell = new Paragraph(projectFocuses.toString(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } document.add(table); document.add(Chunk.NEWLINE); } else { cell.setFont(BODY_TEXT_BOLD_FONT); cell.add(projectFocuses.toString()); cell.add(Chunk.NEWLINE); cell.setFont(BODY_TEXT_FONT); projectFocuses = new StringBuffer(); if (project.isBilateralProject()) { projectFocuses.append( this.getText("summaries.project.ipContributions.noproject", new String[] { "Core" })); } else { projectFocuses.append(this.getText("summaries.project.ipContributions.noproject", new String[] { "Bilateral" })); } cell.add(projectFocuses.toString()); document.add(cell); document.add(Chunk.NEWLINE); } /* * if (project.isBilateralProject()) { * projectFocuses = new StringBuffer(); * cell = new Paragraph(); * cell.setFont(BODY_TEXT_BOLD_FONT); * projectFocuses.append(this.getText("summaries.project.ipContributions.proposal")); * cell.add(projectFocuses.toString()); * cell.setFont(BODY_TEXT_FONT); * cell.add(this.messageReturn(project.getBilateralContractProposalName())); * document.add(cell); * document.add(Chunk.NEWLINE); * } */ } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addProjectLocations() { Paragraph title = new Paragraph("3. " + this.getText("summaries.projectLocation.title"), HEADING3_FONT); Paragraph cell;/* ww w . j a v a 2s. c om*/ StringBuffer projectLocations = new StringBuffer(); List<Location> locationList = (project.getLocations()); PdfPTable table; try { document.newPage(); document.add(title); if (project.isGlobal()) { Image global = Image.getInstance(config.getBaseUrl() + "/images/summaries/global-map.png"); global.scalePercent(60f); global.setAlignment(Element.ALIGN_CENTER); document.add(global); } else if (locationList.isEmpty()) { cell = new Paragraph(); cell.setFont(BODY_TEXT_FONT); cell.add(this.getText("summaries.project.empty")); document.add(cell); } else { table = new PdfPTable(4); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 4, 4, 4, 5 }); table.setHeaderRows(1); // Headers cell = new Paragraph(this.getText("summaries.projectLocation.table.level"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.projectLocation.table.latitude"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.projectLocation.table.longitude"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.projectLocation.table.name"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); double answer = 0; OtherLocation otherLocation; for (Location location : locationList) { answer = 0; projectLocations = new StringBuffer(); // Level if (location.isCountry()) { projectLocations.append("Country"); } else if (location.isRegion()) { projectLocations.append("Region"); } else if (location.isClimateSmartVillage()) { projectLocations.append("CSV"); } else if (location.isOtherLocation()) { otherLocation = (OtherLocation) location; projectLocations.append(otherLocation.getType().getName()); } cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); cell.add(projectLocations.toString()); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); // Latitude projectLocations = new StringBuffer(); if (location.isOtherLocation()) { otherLocation = (OtherLocation) location; answer = otherLocation.getGeoPosition().getLatitude(); cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); if (answer != 0) { cell.add(String.valueOf(answer)); } else { cell.add("Not applicable"); } this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); // Longitude answer = otherLocation.getGeoPosition().getLatitude(); cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); if (answer != 0) { cell.add(String.valueOf(answer)); } else { cell.add("Not applicable"); } this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); } else { // Latitude cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); cell.add("Not applicable"); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); // Longitude cell.add("Not applicable"); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); } // Name cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); projectLocations = new StringBuffer(); projectLocations.append(location.getName()); cell.add(projectLocations.toString()); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); } title = new Paragraph(); title.add(Chunk.NEWLINE); title.add(Chunk.NEWLINE); document.add(title); document.add(table); if (!project.isReporting()) { // Lesson regarding locations Paragraph locationsBlock = new Paragraph(); locationsBlock.setAlignment(Element.ALIGN_JUSTIFIED); locationsBlock.add(Chunk.NEWLINE); locationsBlock.add(Chunk.NEWLINE); locationsBlock.setFont(BODY_TEXT_BOLD_FONT); locationsBlock.add(this.getText("summaries.project.location.lessonRegarding")); locationsBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("locations") != null) { locationsBlock .add(this.messageReturn(project.getComponentLesson("locations").getLessons())); } else { locationsBlock.add(this.messageReturn(null)); } document.add(locationsBlock); } } } catch (DocumentException e) { LOG.error("There was an error trying to add the project locations to the project summary pdf", e); } catch (MalformedURLException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); e.printStackTrace(); } catch (IOException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); e.printStackTrace(); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * This method is used for add Outcomes in the project summary *//*from w w w . jav a 2 s .c om*/ private void addProjectOutcomes(String number) { Paragraph outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); Paragraph title = new Paragraph(number + ". " + this.getText("summaries.project.outcome"), HEADING2_FONT); outcomesBlock.add(title); outcomesBlock.add(Chunk.NEWLINE); ; title = new Paragraph(); title.setFont(HEADING3_FONT); title.add(number + ".1 " + this.getText("summaries.project.outcomeNarrative")); outcomesBlock.add(title); outcomesBlock.add(Chunk.NEWLINE); ; // Project outcome statement Paragraph body = new Paragraph(); body.setFont(BODY_TEXT_BOLD_FONT); body.add(this.getText("summaries.project.outcomeStatement")); // body.setFont(BODY_TEXT_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)) == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement() == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement().equals("")) { body.add(": "); body.setFont(BODY_TEXT_FONT); body.add(this.getText("summaries.project.empty")); } else { body.setFont(BODY_TEXT_FONT); body.add(Chunk.NEWLINE); body.add(this.messageReturn(project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement())); } body.add(Chunk.NEWLINE); ; outcomesBlock.add(body); try { document.newPage(); document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } Anchor anchor; currentPlanningYear--; ////////////////// Reporting PdfPTable table; if (project.isReporting()) { for (int year = currentPlanningYear; year < midOutcomeYear; year++) { // Annual progress towards outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualProgress", new String[] { String.valueOf(year) })); outcomesBlock.setFont(BODY_TEXT_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { outcomesBlock.add( this.messageReturn(project.getOutcomes().get(String.valueOf(year)).getStatement())); } outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); try { document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } if (year == this.currentPlanningYear) { table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(500); ///// outcome toward in reporting cycle outcomesBlock = new Paragraph(); outcomesBlock.setFont(TABLE_BODY_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualTowards", new String[] { String.valueOf(year) })); outcomesBlock.setFont(TABLE_BODY_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { outcomesBlock.add(this .messageReturn(project.getOutcomes().get(String.valueOf(year)).getAnualProgress())); } this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_JUSTIFIED, 1); ///// outcome communication outcomesBlock = new Paragraph(); outcomesBlock.setFont(TABLE_BODY_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualCommunication")); outcomesBlock.setFont(TABLE_BODY_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { outcomesBlock.add(this .messageReturn(project.getOutcomes().get(String.valueOf(year)).getComunication())); } this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_JUSTIFIED, 1); // Any evendence outcomesBlock = new Paragraph(); outcomesBlock.setFont(TABLE_BODY_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualEvidence")); outcomesBlock.setFont(TABLE_BODY_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null || project.getOutcomes().get(String.valueOf(year)).getFile() == null || project.getOutcomes().get(String.valueOf(year)).getFile().equals("")) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { anchor = new Anchor(project.getOutcomes().get(String.valueOf(year)).getFile(), TABLE_BODY_FONT_LINK); anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId() + "/project_outcome/" + project.getOutcomes().get(String.valueOf(year)).getFile()); outcomesBlock.add(anchor); } this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_LEFT, 1); try { document.add(table); outcomesBlock = new Paragraph(); outcomesBlock.add(Chunk.NEWLINE); document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } } } } ////////////////// Planning else { String outcomeProgress = new String(); for (int year = currentPlanningYear; year < midOutcomeYear; year++) { // Annual progress towards outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualProgress", new String[] { String.valueOf(year) })); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null || project.getOutcomes().get(String.valueOf(year)).getStatement() == null || project.getOutcomes().get(String.valueOf(year)).getStatement().equals("")) { outcomesBlock.add(": "); outcomesBlock.setFont(BODY_TEXT_FONT); outcomeProgress = this.getText("summaries.project.empty"); } else { outcomesBlock.add(Chunk.NEWLINE); outcomeProgress = this .messageReturn(project.getOutcomes().get(String.valueOf(year)).getStatement()); outcomesBlock.setFont(BODY_TEXT_FONT); } outcomesBlock.add(outcomeProgress); outcomesBlock.add(Chunk.NEWLINE); ; outcomesBlock.add(Chunk.NEWLINE); ; try { document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } } } // Lesson regardins outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); if (project.isReporting()) { outcomesBlock.add(this.getText("summaries.project.outcome.reporting.lessonRegarding")); } else { outcomesBlock.add(this.getText("summaries.project.outcome.lessonRegarding")); } outcomesBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("outcomes") != null) { outcomesBlock.add(this.messageReturn(project.getComponentLesson("outcomes").getLessons())); } else { outcomesBlock.add(this.messageReturn(null)); } try { document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } // ******************* CCAFS Outcomes***************/ this.addProjectCCAFSOutcomes(number); // ********************************************************************************** // ******************* Other contributions***************/ // ********************************************************************************** OtherContribution otherContribution = project.getIpOtherContribution(); try { outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); title = new Paragraph( number + ".3 " + this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions"), HEADING3_FONT); outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(title); outcomesBlock.add(Chunk.NEWLINE); // Contribution to other Impact Pathways: outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); if (project.isReporting()) { outcomesBlock.add(this.getText( "summaries.project.outcome.ccafs.outcomes.reporting.other.contributions.pathways")); } else { outcomesBlock .add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.pathways")); } outcomesBlock.setFont(BODY_TEXT_FONT); if (otherContribution == null || otherContribution.getContribution() == null || otherContribution.getContribution().equals("")) { outcomesBlock.add(": " + this.getText("summaries.project.empty")); } else { outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(otherContribution.getContribution()); } outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); document.add(outcomesBlock); document.add(Chunk.NEWLINE); Paragraph cell; if (project.isReporting()) { if (project.getOtherContributions().isEmpty()) { } else { table = new PdfPTable(4); table.setWidths(new int[] { 2, 4, 4, 4 }); table.setLockedWidth(true); table.setTotalWidth(500); // adding headers cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.region"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.indicator"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.describe", new String[] { String.valueOf(this.currentReportingYear) }), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.ablequantily"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); // Adding contain for (ProjecteOtherContributions projectOther : project.getOtherContributions()) { cell = new Paragraph(projectOther.getRegion(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(projectOther.getIndicators(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(projectOther.getDescription(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(String.valueOf(projectOther.getTarget()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } document.add(table); document.add(Chunk.NEWLINE); } // // Collaboration with other CRPs cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.collaborating"), BODY_TEXT_BOLD_FONT); if (project.getListCRPContributions().isEmpty()) { cell.add(": "); cell.setFont(BODY_TEXT_FONT); cell.add(this.messageReturn(null)); cell.add(Chunk.NEWLINE); document.add(cell); } else { document.add(cell); document.add(Chunk.NEWLINE); for (CRPContribution crpContribution : project.getListCRPContributions()) { table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(500); cell = new Paragraph(this.messageReturn(crpContribution.getCrp().getName()), TABLE_BODY_BOLD_FONT); cell.setAlignment(Element.ALIGN_LEFT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph( this.getText("summaries.project.reporting.ccafs.outcomes.natureCollaboration"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(crpContribution.getNatureCollaboration())); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); cell = new Paragraph( this.getText("summaries.project.reporting.ccafs.outcomes.achievedOutcome"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(crpContribution.getExplainAchieved())); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); document.add(table); document.add(Chunk.NEWLINE); } } } else { outcomesBlock = new Paragraph(); // Contribution to another Center activity: outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock .add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.center")); outcomesBlock.setFont(BODY_TEXT_FONT); if (otherContribution == null || otherContribution.getAdditionalContribution() == null || otherContribution.getAdditionalContribution().equals("")) { outcomesBlock.add(": " + this.getText("summaries.project.empty")); } else { outcomesBlock.add(otherContribution.getAdditionalContribution()); outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); } boolean addParagraph = false; cell = new Paragraph(); ; cell.setFont(BODY_TEXT_BOLD_FONT); table = new PdfPTable(2); cell.add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.covered")); if (otherContribution != null) { List<CRPContribution> listCRP = otherContribution.getCrpContributions(); if (listCRP.isEmpty()) { cell.setFont(BODY_TEXT_FONT); cell.add(this.getText("summaries.project.empty")); addParagraph = true; } else { table.setWidths(new int[] { 4, 6 }); table.setLockedWidth(true); table.setTotalWidth(500); this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); // adding headers this.addTableHeaderCell(table, new Paragraph( this.getText( "summaries.project.outcome.ccafs.outcomes.other.contributions.crp"), TABLE_HEADER_FONT)); this.addTableHeaderCell(table, new Paragraph(this.getText( "summaries.project.outcome.ccafs.outcomes.other.contributions.nature"), TABLE_HEADER_FONT)); for (CRPContribution CRPContribution : listCRP) { if (CRPContribution != null && CRPContribution.getCrp() != null) { cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); cell.add(CRPContribution.getCrp().getName()); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); cell.add(CRPContribution.getNatureCollaboration()); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } } } } else { cell.add(": "); cell.setFont(BODY_TEXT_FONT); cell.add(this.getText("summaries.project.empty")); addParagraph = true; } document.add(outcomesBlock); // Add paragraphs to document if (addParagraph) { document.add(cell); } else { document.add(table); } document.add(Chunk.NEWLINE); // Lesson regardins Other contributions outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock.add(this .getText("summaries.project.outcome.ccafs.outcomes.other.contributions.lessonRegarding")); outcomesBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("otherContributions") != null) { outcomesBlock .add(this.messageReturn(project.getComponentLesson("otherContributions").getLessons())); } else { outcomesBlock.add(this.messageReturn(null)); } document.add(outcomesBlock); } // ********************************************************************************** // *************************** Outcome Case Studies ************************************* // ********************************************************************************** int counter = 0; if (project.isReporting()) { document.newPage(); title = new Paragraph( number + ".4 " + this.getText("summaries.project.reporting.outcome.case.studies"), HEADING3_FONT); document.add(title); if (project.getCaseStudies().isEmpty()) { document.add( new Paragraph(this.getText("summaries.project.reporting.outcome.not.case.studies"))); } else { title = new Paragraph(); title.add(Chunk.NEWLINE); document.add(title); for (CasesStudies caseStudy : project.getCaseStudies()) { counter++; table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(500); // case study cell = new Paragraph( this.getText("summaries.project.reporting.outcome.case.study") + " #" + counter, TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); // this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE, // table.getNumberOfColumns(), 0, false); // Title cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.title"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getTitle()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Outcome statement cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.outcomestatement"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getOutcomeStatement()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Research outputs cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.researchoutputs"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getResearchOutputs()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Research partners cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.researchPartners"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getResearchPartners()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // activities Contributed cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.activitiesContributed"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getActivities()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Non Research Partners cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.nonResearchPartners"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getNonResearchPartneres()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Output Users cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.outputUsers"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getOutputUsers()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Output Used cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.outputWasUsed"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getOutputUsed()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Evidence cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.evidenceOutcome"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getEvidenceOutcome()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // References cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.references"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getReferencesCase()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Outcome indicators cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.primaryOutcome", new String[] { String.valueOf(this.midOutcomeYear) }), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add("\n"); for (IPIndicator ipIndicator : caseStudy.getCaseStudyIndicators()) { if (ipIndicator.getOutcome() != null) { cell.add(ipIndicator.getOutcome().getDescription()); } cell.add(" " + ipIndicator.getDescription() + "\n"); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Explain link cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.explainLink"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getExplainIndicatorRelation()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // year cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.year"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(String.valueOf(caseStudy.getYear())); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // upload cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.upload"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); if (caseStudy.getFile() == null || caseStudy.getFile().equals("")) { cell.add(this.messageReturn(null)); } else { anchor = new Anchor(caseStudy.getFile(), TABLE_BODY_FONT_LINK); anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId() + "/caseStudy/" + caseStudy.getFile()); cell.add(anchor); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); document.add(table); document.add(new Paragraph(Chunk.NEWLINE)); } } } } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * Entering the project outputs in the summary */// w w w. j av a 2 s .co m private void addProjectOutputs(String number) { // ********************************************************************************** // *************************** Overview By Mog ************************************* // ********************************************************************************** try { Paragraph overview_title = new Paragraph(); overview_title.setFont(HEADING2_FONT); overview_title.add(number + ". " + this.getText("summaries.project.projectOutput")); overview_title.add(Chunk.NEWLINE); overview_title.add(Chunk.NEWLINE); document.newPage(); document.add(overview_title); overview_title = new Paragraph(); overview_title.setFont(HEADING3_FONT); overview_title.add(number + ".1 " + this.getText("summaries.project.overviewbymogs")); document.add(overview_title); } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } int[] years = { midOutcomeYear, project.isReporting() ? this.currentReportingYear - 1 : this.currentReportingYear - 1, project.isReporting() ? this.currentReportingYear : this.currentPlanningYear, project.isReporting() ? this.currentReportingYear + 1 : this.currentReportingYear + 1 }; Paragraph paragraph = new Paragraph(); List<IPElement> mogs = project.getOutputs(); try { if (mogs.isEmpty()) { paragraph.add(this.getText("summaries.project.empty")); document.add(paragraph); } else { // year PdfPTable table; for (int a = 0; a < years.length; a++) { paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.add(this.getText("summaries.project.overviewbymogs.text") + "- " + years[a]); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); this.addTableHeaderCell(table, paragraph); // Mog for (int b = 0; b < mogs.size(); b++) { this.addOverview(table, mogs.get(b), years[a]); } paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); document.add(table); } // Leason regardins paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.setFont(BODY_TEXT_BOLD_FONT); if (!project.isReporting()) { paragraph.add(this.getText("summaries.project.output.lessonRegarding")); } else { paragraph.add(this.getText("summaries.project.overviewbymogs.reporting.lesson")); } paragraph.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("outputs") != null) { paragraph.add(this.messageReturn(project.getComponentLesson("outputs").getLessons())); } else { paragraph.add(this.messageReturn(null)); } paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } // ********************************************************************************** // *************************** Deliverables.**************************************** // ********************************************************************************** int counter = 1; try { document.newPage(); paragraph = new Paragraph(); paragraph.setFont(HEADING3_FONT); paragraph.add(number + ".2 " + this.getText("summaries.project.deliverable.title")); document.add(paragraph); paragraph = new Paragraph(); List<Deliverable> listDeliverables = project.getDeliverables(); if (listDeliverables.isEmpty()) { paragraph.add(this.getText("summaries.project.empty")); document.add(paragraph); } else { paragraph.add(Chunk.NEWLINE); document.add(paragraph); for (Deliverable deliverable : listDeliverables) { if (!project.isReporting()) { if (deliverable.getYear() == config.getPlanningCurrentYear()) { this.addDelivable(deliverable, counter); counter++; } } } } // ********************************************************************************** // *************************** Next users.**************************************** // ********************************************************************************** if (project.isReporting()) { counter = 1; document.newPage(); paragraph = new Paragraph(); paragraph.setFont(HEADING3_FONT); paragraph.add(number + ".3 " + this.getText("summaries.project.reporting.nextuser.title")); document.add(paragraph); PdfPTable table; if (project.getNextUsers().isEmpty()) { paragraph = new Paragraph(); paragraph.add(this.messageReturn(null)); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } else { paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); for (ProjectNextUser projectNextUser : project.getNextUsers()) { paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.setAlignment(Element.ALIGN_LEFT); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); paragraph.add(this.getText("summaries.project.reporting.nextuser", new String[] { String.valueOf(counter) })); this.addTableHeaderCell(table, paragraph); // Next users key paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.currentPeriod")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getKeyNextUser())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // Strategies paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.strategies")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getStrategies())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // reported paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.reported")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getReportedDeliverables())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // lessons paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.lessons")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getLessonsImplications())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); counter++; document.add(table); paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } } // ********************************************************************************** // *************************** Project HighLights**************************************** // ********************************************************************************** counter = 1; document.newPage(); paragraph = new Paragraph(); paragraph.setFont(HEADING3_FONT); paragraph.add(number + ".4 " + this.getText("summaries.project.reporting.highlight.principal")); document.add(paragraph); paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); for (ProjectHighligths projectHighLigth : project.getHighlights()) { table = new PdfPTable(2); table.setLockedWidth(true); table.setTotalWidth(480); paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight", new String[] { String.valueOf(counter) })); this.addTableHeaderCellColspan(table, paragraph, 2); // title paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.title")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getTitle())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // author paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.author")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getAuthor())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // subject paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.subject")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getSubject())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // publisher paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.publisher")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getPublisher())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // year paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.year")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getYear()))); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // project highlight types paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.types")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { for (ProjectHighligthsTypes projectHighLigthTypes : projectHighLigth .getProjectHighligthsTypeses()) { paragraph.add(this.messageReturn("\n" + ProjectHighlightsType .getEnum(String.valueOf(projectHighLigthTypes.getIdType())).getDescription())); } } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // project images paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add("Image"); if (projectHighLigth != null) { Image global; try { if (projectHighLigth.getPhoto() != null) { String urlImage = config.getDownloadURL() + "/" + this.getHighlightsImagesUrlPath() + projectHighLigth.getPhoto(); urlImage = urlImage.replace(" ", "%20"); global = Image.getInstance(urlImage); } else { global = null; } if (global != null) { float documentWidth = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(); float documentHeight = document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin(); global.scaleToFit((float) (documentWidth * 0.4), global.getHeight()); global.setAlignment(Element.ALIGN_CENTER); this.addTableBodyCell(table, global, Element.ALIGN_LEFT, 1); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { paragraph.add(this.messageReturn(null)); } // project start date paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.startDate")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getStartDate()))); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // project end date paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.endDate")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getEndDate()))); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // Its Global paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.itsglobal")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { if (projectHighLigth.isIsGlobal()) { paragraph.add("Yes"); } else { paragraph.add("No"); } ; } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Country paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.country")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null && projectHighLigth.getProjectHighligthsCountries() != null) { for (ProjectHighligthsCountry country : projectHighLigth.getProjectHighligthsCountries()) { paragraph.add(locationManager.getCountry(country.getIdCountry()).getName() + "\n"); } } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.keywords")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getKeywords())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // description paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.description")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getDescription())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Introduction / Objectives paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.introduction")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getObjectives())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Results paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.results")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getResults())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Partners paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.partners")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getPartners())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Links paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.links")); paragraph.setFont(TABLE_BODY_FONT); paragraph.add(this.messageReturn(projectHighLigth.getLinks())); this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); document.add(table); document.newPage(); } } } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } }
From source file:org.cocktail.superplan.server.gestionimpression.TabularEdtReport.java
License:CeCILL license
public NSData genererPdf(NSArray creneaux, NSTimestamp debutSemaine, String semaine, String libelleFormation) throws DocumentException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter.getInstance(document, os); document.open();/*from w w w .j a va 2s .c om*/ document.setMargins(0, 0, 0, 0); Font font = new Font(Font.TIMES_ROMAN, 12, Font.BOLD, Color.DARK_GRAY); PdfPTable headerTable = new PdfPTable(1); PdfPCell cell = new PdfPCell(); Phrase ph = new Phrase(); ph.add(new Chunk(libelleFormation, font)); cell.setPhrase(ph); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); font = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, Color.DARK_GRAY); cell = new PdfPCell(); ph = new Phrase(); ph.add(new Chunk(semaine, font)); cell.setPhrase(ph); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); headerTable.setWidthPercentage(100); headerTable.setSpacingAfter(5.0f); document.add(headerTable); PdfPTable pdfTable = creerCreneauxTable(creneaux, debutSemaine); pdfTable.setWidthPercentage(100); document.add(pdfTable); document.close(); return new NSData(os.toByteArray()); }
From source file:org.cocktail.superplan.server.gestionimpression.TabularEdtReport.java
License:CeCILL license
public PdfPTable creerCreneauxTable(NSArray creneaux, NSTimestamp debutSemaine) { PdfPTable pdfTable = new PdfPTable(4); Object currentObjet;// w w w . ja v a 2 s . c om NSDictionary creneau; Integer jour; NSMutableArray lun, mar, mer, jeu, ven, sam, dim; lun = new NSMutableArray(); mar = new NSMutableArray(); mer = new NSMutableArray(); jeu = new NSMutableArray(); ven = new NSMutableArray(); sam = new NSMutableArray(); dim = new NSMutableArray(); for (int i = 0; i < creneaux.count(); i++) { currentObjet = creneaux.objectAtIndex(i); if (currentObjet instanceof NSArray) { creneau = (NSDictionary) ((NSArray) currentObjet).objectAtIndex(0); } else { creneau = (NSDictionary) currentObjet; } jour = (Integer) creneau.valueForKey("jour"); switch (jour.intValue()) { case Calendar.MONDAY: lun.addObject(currentObjet); break; case Calendar.TUESDAY: mar.addObject(currentObjet); break; case Calendar.WEDNESDAY: mer.addObject(currentObjet); break; case Calendar.THURSDAY: jeu.addObject(currentObjet); break; case Calendar.FRIDAY: ven.addObject(currentObjet); break; case Calendar.SATURDAY: sam.addObject(currentObjet); break; case Calendar.SUNDAY: dim.addObject(currentObjet); break; } } GregorianCalendar cal = new GregorianCalendar(); cal.setTime(debutSemaine); NSTimestamp dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Lundi", lun, dSemaine, pdfTable); cal.add(Calendar.DAY_OF_YEAR, 1); dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Mardi", mar, dSemaine, pdfTable); cal.add(Calendar.DAY_OF_YEAR, 1); dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Mercredi", mer, dSemaine, pdfTable); cal.add(Calendar.DAY_OF_YEAR, 1); dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Jeudi", jeu, dSemaine, pdfTable); cal.add(Calendar.DAY_OF_YEAR, 1); dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Vendredi", ven, dSemaine, pdfTable); cal.add(Calendar.DAY_OF_YEAR, 1); dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Samedi", sam, dSemaine, pdfTable); cal.add(Calendar.DAY_OF_YEAR, 1); dSemaine = new NSTimestamp(cal.getTime()); ecrireCreneauxJour("Dimanche", dim, dSemaine, pdfTable); return pdfTable; }
From source file:org.cyberoam.iview.charts.Chart.java
License:Open Source License
/** * Function to write a given ChartID to pdf file * @param pdfFileName specifies the pdf where chart is written.Please specify full path with the filename. * @param reportGroup id specifies the chart to be generated * @param startdate specifies start date * @param enddate specifies end date//from w w w.ja va 2s .co m * @param limit specifies number of records per record to be written in report */ public static void generatePDFReportGroup(OutputStream out, int reportGroupID, String applianceID, String startDate, String endDate, String limit, int[] deviceIDs, HttpServletRequest request, LinkedHashMap paramMap) throws Exception { float width = 768; float height = 1024; float rec_hieght = 470; Rectangle pagesize = new Rectangle(768, 1024); Document document = new Document(pagesize, 30, 30, 30, 30); JFreeChart chart = null; SqlReader sqlReader = new SqlReader(false); //CyberoamLogger.sysLog.debug("pdf:"+pdfFileName); CyberoamLogger.sysLog.debug("reportGroupID:" + reportGroupID); CyberoamLogger.sysLog.debug("applianceID:" + applianceID); CyberoamLogger.sysLog.debug("startDate:" + startDate); CyberoamLogger.sysLog.debug("endDate:" + endDate); CyberoamLogger.sysLog.debug("limit:" + limit); try { //PdfWriter writer = PdfWriter.getInstance(document, response!=null ? response.getOutputStream():new FileOutputStream(pdfFileName)); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setPageEvent(new Chart()); document.addAuthor("iView"); document.addSubject("iView Report"); document.open(); PdfContentByte contentByte = writer.getDirectContent(); ReportGroupBean reportGroupBean = ReportGroupBean.getRecordbyPrimarykey(reportGroupID); ArrayList reportList = reportGroupBean.getReportIdByReportGroupId(reportGroupID); ReportBean reportBean; ResultSetWrapper rsw = null; String seperator = System.getProperty("file.separator"); //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator + "iViewPDF.jpg"; String path = InitServlet.contextPath + seperator + "images" + seperator + "iViewPDF.jpg"; Image iViewImage = Image.getInstance(path); iViewImage.scaleAbsolute(750, 900); //iViewImage.scaleAbsolute(600,820); iViewImage.setAbsolutePosition(10, 10); document.add(iViewImage); document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); /* * Generating Table on the First Page of Report providing summary of Content */ PdfPTable frontPageTable = new PdfPTable(2); PdfPCell dataCell; ReportGroupRelationBean reportGroupRelationBean; String reportName = ""; Color tableHeadBackColor = new Color(150, 174, 190); Color tableContentBackColor = new Color(229, 232, 237); Color tableBorderColor = new Color(229, 232, 237); dataCell = new PdfPCell(new Phrase(new Chunk("Report Profile", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255))))); dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); /** * Getting dynamic title. */ String title = ""; if (paramMap != null) { title = paramMap.get("title").toString(); paramMap.remove("title"); } if (request != null) title = getFormattedTitle(request, reportGroupBean, true); dataCell = new PdfPCell(new Phrase(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255))))); dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Start Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(startDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("End Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(endDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("iView Server Time", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); java.util.Date currentDate = new java.util.Date(); dataCell = new PdfPCell(new Phrase(currentDate.toString())); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Reports", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); int len = reportList.size(); for (int k = 0; k < len; k++) { reportGroupRelationBean = (ReportGroupRelationBean) reportList.get(k); reportName += " " + (k + 1) + ". " + ReportBean.getRecordbyPrimarykey(reportGroupRelationBean.getReportId()).getTitle() + "\n"; } dataCell = new PdfPCell(new Phrase("\n" + reportName + "\n")); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Device Names (IP Address)", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); DeviceBean deviceBean = null; String deviceNameWithIP = ""; if (deviceIDs != null) { for (int i = 0; i < deviceIDs.length; i++) { deviceBean = DeviceBean.getRecordbyPrimarykey(deviceIDs[i]); if (deviceBean != null) { deviceNameWithIP += " " + (i + 1) + ". " + deviceBean.getName() + " (" + deviceBean.getIp() + ")\n"; } } } dataCell = new PdfPCell(new Phrase("\n" + deviceNameWithIP + "\n")); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); /* * Adding Table to PDF */ document.add(frontPageTable); /* * Adding Charts and Table to PDF */ for (int i = 0; i < reportList.size(); i++) { document.newPage(); reportBean = ReportBean .getRecordbyPrimarykey(((ReportGroupRelationBean) reportList.get(i)).getReportId()); String query = null; if (request == null) { query = PrepareQuery.getQuery(reportBean, startDate, endDate, applianceID, null, null, "0", limit, paramMap); } else { PrepareQuery prepareQuery = new PrepareQuery(); query = prepareQuery.getQuery(reportBean, request); } CyberoamLogger.sysLog.debug("PDF:ReportID:" + reportBean.getReportId() + "Query->" + query); try { rsw = sqlReader.getInstanceResultSetWrapper(query); } catch (org.postgresql.util.PSQLException e) { if (query.indexOf("5min_ts_20") > -1) { query = query.substring(0, query.indexOf("5min_ts_20")) + "4hr" + query.substring(query.indexOf("5min_ts_20") + 16, query.length()); CyberoamLogger.appLog.debug("New query : " + query); rsw = sqlReader.getInstanceResultSetWrapper(query); } else { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); } } catch (Exception e) { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); rsw.close(); } /* * PDF Rendering work starts here */ for (int j = 0; j < (int) (rec_hieght / 16) + 1; j++) { document.add(new Paragraph("\n")); } // This fix is to resolve the problems associated with reports which don't have graphs. // If there is no graph associated with the report than no need to generate //a chart for it. GraphBean graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getReportId()); //if(graphBean!=null) if (reportBean.getReportFormatId() != 2) { chart = Chart.getChart(reportBean.getReportId(), rsw, null); PdfTemplate pdfTemplate = contentByte.createTemplate(width, height); Graphics2D graphics2D = pdfTemplate.createGraphics(width, height); Rectangle2D rectangle = new Rectangle2D.Double(100, 85, 540, rec_hieght); chart.draw(graphics2D, rectangle); graphics2D.dispose(); contentByte.addTemplate(pdfTemplate, 0, 0); } else { Paragraph p = new Paragraph(reportBean.getTitle() + "\n\n", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD)); p.setAlignment("center"); document.add(p); } // Retrieving PdfPTable PdfPTable pdfTable = getPdfPTable(reportBean, rsw); rsw.close(); /* * Adding Table to PDF */ document.add(pdfTable); } CyberoamLogger.appLog.info("*************Finishing Chart****************"); } catch (Exception e) { CyberoamLogger.sysLog.debug("Chart.writeChartToPDF.e" + e.getMessage(), e); } finally { sqlReader.close(); } document.close(); }
From source file:org.cyberoam.iview.charts.Chart.java
License:Open Source License
/** * Function for getting report PdfPtable instance for given report and record set * @param report bean specifies the report for which table is generated * @param rsw specifies Result set collection * @return instance of PdfPtable//from ww w. j a v a 2 s . co m */ public static PdfPTable getPdfPTable(ReportBean reportBean, ResultSetWrapper rsw) { PdfPTable pdfTable = null; try { rsw.last(); //int rowCount=rsw.getRow(); ReportColumnBean[] reportColumns = (ReportColumnBean[]) ReportColumnBean .getReportColumnsByReportID(reportBean.getReportId()).toArray(new ReportColumnBean[0]); pdfTable = new PdfPTable(reportColumns.length); // Adding Column Name to PDF Table PdfPCell headCell; for (int count = 0; count < reportColumns.length; count++) { headCell = new PdfPCell(new Phrase(18, new Chunk(reportColumns[count].getColumnName(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.BOLD, Color.blue)))); headCell.setBackgroundColor(new Color(238, 238, 238)); pdfTable.addCell(headCell); } String data; int i = 0; rsw.beforeFirst(); while (rsw.next()) { for (int j = 0; j < reportColumns.length; j++) { if (reportColumns[j].getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) { data = ByteInUnit.getBytesInUnit(rsw.getLong(reportColumns[j].getDbColumnName())); } else if (reportColumns[j].getColumnFormat() == TabularReportConstants.PERCENTAGE_FORMATTING) { data = rsw.getString(reportColumns[j].getDbColumnName()) + " %"; } else if (reportColumns[j].getColumnFormat() == TabularReportConstants.DECODE_FORMATTING) { data = URLDecoder.decode(rsw.getString(reportColumns[j].getDbColumnName())); } else if (reportColumns[j].getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING) { int index = rsw.getString(reportColumns[j].getDbColumnName()).indexOf(':'); if (index != -1) { data = ProtocolBean.getProtocolNameById(Integer.parseInt( rsw.getString(reportColumns[j].getDbColumnName()).substring(0, index))); data = data + rsw.getString(reportColumns[j].getDbColumnName()).substring(index, rsw.getString(reportColumns[j].getDbColumnName()).length()); } else { data = rsw.getString(reportColumns[j].getDbColumnName()); } } else if (reportColumns[j].getColumnFormat() == TabularReportConstants.SEVERITY_FORMATTING) { data = TabularReportConstants .getSeverity(rsw.getString(reportColumns[j].getDbColumnName())); } else if (reportColumns[j].getColumnFormat() == TabularReportConstants.ACTION_FORMATTING) { data = TabularReportConstants.getAction(rsw.getString(reportColumns[j].getDbColumnName())); } else { data = rsw.getString(reportColumns[j].getDbColumnName()); } if (data == null || "".equalsIgnoreCase(data)) data = "N/A"; pdfTable.addCell(data); } i++; } } catch (SQLException e) { CyberoamLogger.sysLog.debug("Chart.getPDFPTable.e" + e, e); } return pdfTable; }
From source file:org.cyberoam.iview.charts.Chart.java
License:Open Source License
public static void generatePDFReport(OutputStream out, int reportID, String applianceID, String startDate, String endDate, String limit, int[] deviceIDs, HttpServletRequest request, int reportGroupID, LinkedHashMap paramMap) throws Exception { float width = 768; float height = 1024; float rec_hieght = 470; Rectangle pagesize = new Rectangle(768, 1024); Document document = new Document(pagesize, 30, 30, 30, 30); IndexManager indexManager = null;//from ww w .j ava 2 s .c om JFreeChart chart = null; SqlReader sqlReader = new SqlReader(false); CyberoamLogger.sysLog.debug("reportID:" + reportID); CyberoamLogger.sysLog.debug("applianceID:" + applianceID); CyberoamLogger.sysLog.debug("startDate:" + startDate); CyberoamLogger.sysLog.debug("endDate:" + endDate); CyberoamLogger.sysLog.debug("limit:" + limit); try { //PdfWriter writer = PdfWriter.getInstance(document, response!=null ? response.getOutputStream():new FileOutputStream(pdfFileName)); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setPageEvent(new Chart()); document.addAuthor("iView"); document.addSubject("iView Report"); document.open(); PdfContentByte contentByte = writer.getDirectContent(); //ReportGroupBean reportGroupBean=ReportGroupBean.getRecordbyPrimarykey(reportGroupID); //ArrayList reportList=reportGroupBean.getReportIdByReportGroupId(reportGroupID); ReportBean reportBean; ResultSetWrapper rsw = null; String seperator = System.getProperty("file.separator"); // String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator; String path = InitServlet.contextPath + seperator + "images" + seperator + "iViewPDF.jpg"; /* * Loading Image to add into PDF */ Image iViewImage = Image.getInstance(path); iViewImage.scaleAbsolute(750, 900); //iViewImage.scaleAbsolute(600,820); iViewImage.setAbsolutePosition(10, 10); /*Image headerImage= Image.getInstance(path+ "iViewPDFHeader.jpg"); PdfPTable headerTable = new PdfPTable(2); PdfPCell cell = new PdfPCell(headerImage); headerTable.addCell(cell); HeaderFooter docHeader=null; //document.setHeader(new HeaderFooter(new Phrase(new Chunk())), true); */ document.add(iViewImage); document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); /* * Generating Table on the First Page of Report providing summary of Content */ PdfPTable frontPageTable = new PdfPTable(2); PdfPCell dataCell; String reportName = ""; Color tableHeadBackColor = new Color(150, 174, 190); Color tableContentBackColor = new Color(229, 232, 237); Color tableBorderColor = new Color(229, 232, 237); dataCell = new PdfPCell(new Phrase(new Chunk("Report Profile", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255))))); dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); if (paramMap != null) { reportName = paramMap.get("title").toString(); paramMap.remove("title"); } if (request != null) { ReportGroupBean reportGroupBean = ReportGroupBean.getRecordbyPrimarykey(reportGroupID); reportName = getFormattedTitle(request, reportGroupBean, true); } dataCell = new PdfPCell(); dataCell.addElement(new Phrase(new Chunk(reportName, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255))))); //dataCell.addElement(new Phrase(new Chunk(ReportBean.getRecordbyPrimarykey(reportID).getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11, Font.PLAIN, new Color(10,10,10))))); if (request != null) { dataCell.addElement(new Phrase(new Chunk(reportName + " >> ", FontFactory .getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255))))); dataCell.addElement( new Phrase(new Chunk(ReportBean.getRecordbyPrimarykey(reportID).getTitle(), FontFactory .getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255))))); } dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Start Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(startDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("End Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(endDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("iView Server Time", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); java.util.Date currentDate = new java.util.Date(); dataCell = new PdfPCell(new Phrase(currentDate.toString())); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Device Names (IP Address)", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); DeviceBean deviceBean = null; String deviceNameWithIP = ""; if (deviceIDs != null) { for (int i = 0; i < deviceIDs.length; i++) { deviceBean = DeviceBean.getRecordbyPrimarykey(deviceIDs[i]); if (deviceBean != null) { deviceNameWithIP += " " + (i + 1) + ". " + deviceBean.getName() + " (" + deviceBean.getIp() + ")\n"; } } } dataCell = new PdfPCell(new Phrase("\n" + deviceNameWithIP + "\n")); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); /* * Adding Table to PDF */ document.add(frontPageTable); /* * Adding Charts and Table to PDF */ document.newPage(); reportBean = ReportBean.getRecordbyPrimarykey(reportID); String query = null; if (request == null) { query = PrepareQuery.getQuery(reportBean, startDate, endDate, applianceID, null, null, "0", limit, paramMap); } else { PrepareQuery prepareQuery = new PrepareQuery(); query = prepareQuery.getQuery(reportBean, request); } String searchQuery = ""; if (request == null) { searchQuery = null; } else { searchQuery = request.getParameter("searchquery"); } if (searchQuery != null && !"".equalsIgnoreCase(searchQuery)) { query = query.replaceFirst("where", "where " + searchQuery + " and"); } CyberoamLogger.sysLog.debug("PDF:ReportID:" + reportBean.getReportId() + "Query->" + query); try { if (query.indexOf("select") == -1 && query.indexOf("SELECT") == -1) { indexManager = new IndexManager(); rsw = indexManager.getSearch(query); //rsw=indexManager.getResutSetFromArrayList(searchRecord); } else { rsw = sqlReader.getInstanceResultSetWrapper(query); } } catch (org.postgresql.util.PSQLException e) { if (query.indexOf("5min_ts_20") > -1) { query = query.substring(0, query.indexOf("5min_ts_20")) + "4hr" + query.substring(query.indexOf("5min_ts_20") + 16, query.length()); CyberoamLogger.appLog.debug("New query : " + query); rsw = sqlReader.getInstanceResultSetWrapper(query); } else { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); } } catch (Exception e) { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); rsw.close(); } /* * PDF Rendering work starts here */ //if(Integer.parseInt(limit)<=10 && query.indexOf("where")>-1){ if (reportBean.getReportFormatId() != 2) { chart = Chart.getChart(reportBean.getReportId(), rsw, null); PdfTemplate pdfTemplate = contentByte.createTemplate(width, height); Graphics2D graphics2D = pdfTemplate.createGraphics(width, height); Rectangle2D rectangle = new Rectangle2D.Double(100, 85, 540, rec_hieght); chart.draw(graphics2D, rectangle); graphics2D.dispose(); contentByte.addTemplate(pdfTemplate, 0, 0); for (int j = 0; j < (int) (rec_hieght / 16) + 1; j++) { document.add(new Paragraph("\n")); } } else document.add(new Paragraph("\n")); // Retrieving PdfPTable PdfPTable pdfTable = getPdfPTable(reportBean, rsw); rsw.close(); document.add(pdfTable); CyberoamLogger.appLog.info("*************Finishing PDF Work****************"); } catch (Exception e) { CyberoamLogger.sysLog.debug("Chart.writeChartToPDF.e" + e.getMessage(), e); } finally { sqlReader.close(); } document.close(); }
From source file:org.cyberoam.iview.charts.Chart.java
License:Open Source License
/** * This Event handler Method adds Header and Footer in PDF File *//*from ww w . j a va 2s . c o m*/ public void onEndPage(PdfWriter writer, Document document) { try { if (document.getPageNumber() > 1) { String seperator = System.getProperty("file.separator"); //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator; String path = InitServlet.contextPath + seperator + "images" + seperator; Image imgHead = Image.getInstance(path + "iViewPDFHeader.JPG"); Image imgFoot = Image.getInstance(path + "iViewPDFFooter.JPG"); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(1); head.addCell(imgHead); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin() - 10, page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); PdfPTable foot = new PdfPTable(1); foot.addCell(imgFoot); foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin() - 10, document.bottomMargin() + 24, writer.getDirectContent()); } } catch (Exception e) { throw new ExceptionConverter(e); } }