List of usage examples for com.lowagie.text Chunk NEWLINE
Chunk NEWLINE
To view the source code for com.lowagie.text Chunk NEWLINE.
Click Source Link
From source file:gov.utah.health.uper.reports.Registration.java
/** * Builds Footer Information/*from w ww . jav a 2s. c om*/ * @param document * @throws DocumentException */ private void buildFooter(Document document) throws DocumentException { Paragraph preface = new Paragraph(FOOTER, footerFont); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); document.add(Chunk.NEWLINE); preface = new Paragraph(FOOTER_WARN, footerFontBold); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); preface = new Paragraph(FOOTER_WARNING, footerFontBold); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); }
From source file:org.apache.poi.xwpf.converter.internal.itext.PDFMapper.java
License:Open Source License
@Override protected void visitEmptyRun(IITextContainer paragraphContainer) throws Exception { ExtendedParagraph pdfParagraph = (ExtendedParagraph) paragraphContainer; pdfParagraph.add(Chunk.NEWLINE); }
From source file:org.apache.poi.xwpf.converter.internal.itext.PDFMapper.java
License:Open Source License
@Override protected void visitRun(XWPFRun run, IITextContainer pdfContainer) throws Exception { CTR ctr = run.getCTR();/* w w w.ja va2 s. c o m*/ // Get family name // Get CTRPr from style+defaults CTString rStyle = getRStyle(run); CTRPr runRprStyle = getRPr(super.getXWPFStyle(rStyle != null ? rStyle.getVal() : null)); CTRPr rprStyle = getRPr(super.getXWPFStyle(run.getParagraph().getStyleID())); CTRPr rprDefault = getRPr(defaults); // Font family String fontFamily = getFontFamily(run, rprStyle, rprDefault); // Get font size float fontSize = run.getFontSize(); // Get font style int fontStyle = Font.NORMAL; if (isBold(run, runRprStyle, rprStyle, rprDefault)) { fontStyle |= Font.BOLD; } if (isItalic(run, runRprStyle, rprStyle, rprDefault)) { fontStyle |= Font.ITALIC; } // Process color Color fontColor = null; String hexColor = getFontColor(run, runRprStyle, rprStyle, rprDefault); if (StringUtils.isNotEmpty(hexColor)) { if (hexColor != null && !"auto".equals(hexColor)) { fontColor = ColorRegistry.getInstance().getColor("0x" + hexColor); } } // Get font Font font = XWPFFontRegistry.getRegistry().getFont(fontFamily, options.getFontEncoding(), fontSize, fontStyle, fontColor); UnderlinePatterns underlinePatterns = run.getUnderline(); boolean singleUnderlined = false; switch (underlinePatterns) { case SINGLE: singleUnderlined = true; break; default: break; } List<CTBr> brs = ctr.getBrList(); for (@SuppressWarnings("unused") CTBr br : brs) { pdfContainer.addElement(Chunk.NEWLINE); } List<CTText> texts = run.getCTR().getTList(); for (CTText ctText : texts) { Chunk aChunk = new Chunk(ctText.getStringValue(), font); if (singleUnderlined) aChunk.setUnderline(1, -2); pdfContainer.addElement(aChunk); } super.visitPictures(run, pdfContainer); // <w:lastRenderedPageBreak /> List<CTEmpty> lastRenderedPageBreakList = ctr.getLastRenderedPageBreakList(); if (lastRenderedPageBreakList != null && lastRenderedPageBreakList.size() > 0) { // IText Document#newPage must be called to generate page break. // But before that, CTSectPr must be getted to compute pageSize, // margins... // The CTSectPr <w:pPr><w:sectPr w:rsidR="00AA33F7" // w:rsidSect="00607077"><w:pgSz w:w="16838" w:h="11906" // w:orient="landscape" />... Stack<CTSectPr> sectPrStack = getSectPrStack(); if (sectPrStack != null && !sectPrStack.isEmpty()) { CTSectPr sectPr = sectPrStack.pop(); applySectPr(sectPr); } for (CTEmpty lastRenderedPageBreak : lastRenderedPageBreakList) { pdfDocument.newPage(); } } }
From source file:org.areasy.common.doclet.document.Members.java
License:Open Source License
/** * Prints member information./*from ww w . ja v a 2 s . c om*/ * * @param declaration The modifiers ("public static final.."). * @param returnType Phrase with the return type text (might be * a hyperlink) * @param parms Parameters of a method or constructor, null for a field. * @param thrownExceptions Exceptions of a method, null for a field or constructor. * @param isFirst True if it is the first field/method/constructor in the list. * @param isField True if it is a field. * @param isConstructor True if it is a constructor. * @throws Exception */ public static void printMember(String declaration, Phrase returnType, ProgramElementDoc commentDoc, Parameter[] parms, ClassDoc[] thrownExceptions, boolean isFirst, boolean isField, boolean isConstructor, boolean isDeprecated, Phrase deprecatedPhrase, Object constantValue) throws Exception { String name = commentDoc.name(); State.setCurrentMember(State.getCurrentClass() + "." + name); State.setCurrentDoc(commentDoc); // Returns the text, resolving any "inheritDoc" inline tags String commentText = DocletUtility.getComment(commentDoc); // TODO: The following line may set the wrong page number // in the index, when the member gets printed on a // new page completely (because it is in one table). // Solution unknown yet. Probably split up table. Doclet.getIndex().addToMemberList(State.getCurrentMember()); // Prepare list of exceptions (if it throws any) String throwsText = "throws"; int parmsColumn = declaration.length() + (name.length() - throwsText.length()); // First output text line (declaration of method and first parameter or "()" ). // This first line is a special case because the class name is bold, // while the rest is regular plain text, so it must be built using three Chunks. Paragraph declarationParagraph = new Paragraph((float) 10.0); // left part / declaration ("public static..") Chunk leftPart = new Chunk(declaration, Fonts.getFont(CODE_FONT, 10)); declarationParagraph.add(leftPart); if (returnType != null) { // left middle part / declaration ("public static..") declarationParagraph.add(returnType); declarationParagraph.add(new Chunk(" ", Fonts.getFont(CODE_FONT, 10))); parmsColumn = 2; } // right middle part / bold class name declarationParagraph.add(new Chunk(name, Fonts.getFont(CODE_FONT, BOLD, 10))); if (!isField) { // 1st parameter or empty brackets if ((parms != null) && (parms.length > 0)) { Phrase wholePhrase = new Phrase("(", Fonts.getFont(CODE_FONT, 10)); // create link for parameter type wholePhrase.add(PDFUtility.getParameterTypePhrase(parms[0], 10)); // then normal text for parameter name wholePhrase.add(" " + parms[0].name()); if (parms.length > 1) { wholePhrase.add(","); } else { wholePhrase.add(")"); } // In order to have the parameter types in the bookmark, // make the current state text more detailled String txt = State.getCurrentMethod() + "("; for (int i = 0; i < parms.length; i++) { if (i > 0) txt = txt + ","; txt = txt + DocletUtility.getParameterType(parms[i]); } txt = txt + ")"; State.setCurrentMethod(txt); // right part / parameter and brackets declarationParagraph.add(wholePhrase); } else { String lastPart = "()"; State.setCurrentMethod(State.getCurrentMethod() + lastPart); // right part / parameter and brackets declarationParagraph.add(new Chunk(lastPart, Fonts.getFont(CODE_FONT, 10))); } } float[] widths = { (float) 6.0, (float) 94.0 }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage((float) 100); // Before the first constructor or method, create a coloured title bar if (isFirst) { PdfPCell colorTitleCell = null; // Some empty space... Document.add(new Paragraph((float) 6.0, " ")); if (isConstructor) colorTitleCell = new CustomPdfPCell("Constructors"); else if (isField) colorTitleCell = new CustomPdfPCell("Fields"); else colorTitleCell = new CustomPdfPCell("Methods"); colorTitleCell.setColspan(2); table.addCell(colorTitleCell); } // Method name (large, first line of a method description block) Phrase linkPhrase = Destinations.createDestination(commentDoc.name(), commentDoc, Fonts.getFont(TEXT_FONT, BOLD, 14)); Paragraph nameTitle = new Paragraph(linkPhrase); PdfPCell nameCell = new CellNoBorderNoPadding(nameTitle); if (isFirst) nameCell.setPaddingTop(10); else nameCell.setPaddingTop(0); nameCell.setPaddingBottom(8); nameCell.setColspan(1); // Create nested table in order to try to prevent the stuff inside // this table from being ripped appart over a page break. The method // name and the declaration/parm/exception line(s) should always be // together, because everything else just looks bad PdfPTable linesTable = new PdfPTable(1); linesTable.addCell(nameCell); linesTable.addCell(new CellNoBorderNoPadding(declarationParagraph)); if (!isField) { // Set up following declaration lines Paragraph[] params = PDFUtility.createParameters(parmsColumn, parms); Paragraph[] exceps = PDFUtility.createExceptions(parmsColumn, thrownExceptions); for (int i = 0; i < params.length; i++) { linesTable.addCell(new CellNoBorderNoPadding(params[i])); } for (int i = 0; i < exceps.length; i++) { linesTable.addCell(new CellNoBorderNoPadding(exceps[i])); } } // Create cell for inserting the nested table into the outer table PdfPCell cell = new PdfPCell(linesTable); cell.setPadding(5); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); table.addCell(cell); // The empty, left cell (the invisible indentation column) State.setContinued(true); PdfPCell leftCell = PDFUtility.createElementCell(5, new Phrase("", Fonts.getFont(TEXT_FONT, BOLD, 6))); PdfPCell spacingCell = new PdfPCell(); spacingCell.setFixedHeight((float) 8.0); spacingCell.setBorder(Rectangle.NO_BORDER); table.addCell(spacingCell); table.addCell(spacingCell); // The descriptive method explanation text if (isDeprecated) { Phrase commentPhrase = new Phrase(); commentPhrase .add(new Phrase(AbstractConfiguration.LB_DEPRECATED_TAG, Fonts.getFont(TEXT_FONT, BOLD, 10))); commentPhrase.add(deprecatedPhrase); table.addCell(leftCell); table.addCell(PDFUtility.createElementCell(0, commentPhrase)); commentPhrase = new Phrase(); commentPhrase.add(Chunk.NEWLINE); table.addCell(leftCell); table.addCell(PDFUtility.createElementCell(0, commentPhrase)); } Element[] objs = HtmlParserWrapper.createPdfObjects(commentText); if (objs.length == 1) { table.addCell(leftCell); table.addCell(PDFUtility.createElementCell(0, objs[0])); } else { table.addCell(leftCell); table.addCell(PDFUtility.createElementCell(0, Element.ALIGN_LEFT, objs)); } // TODO: FORMAT THIS CONSTANT VALUE OUTPUT CORRECTLY if (isField) { if (constantValue != null) { // Add 2nd comment line (left cell empty, right cell text) Chunk valueTextChunk = new Chunk("Constant value: ", Fonts.getFont(TEXT_FONT, PLAIN, 10)); Chunk valueContentChunk = new Chunk(constantValue.toString(), Fonts.getFont(CODE_FONT, BOLD, 10)); Phrase constantValuePhrase = new Phrase(""); constantValuePhrase.add(valueTextChunk); constantValuePhrase.add(valueContentChunk); table.addCell(leftCell); table.addCell(PDFUtility.createElementCell(0, constantValuePhrase)); } } // Add whole method block to document Document.add(table); }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java
License:Open Source License
/** * This method is used for add the main information table of project summary */// ww w .j av a 2 s . c o m private void addMainInformationTable() { String startDate, endDate; if (project.getStartDate() != null) { startDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getStartDate()); } else { startDate = this.messageReturn(null); } if (project.getEndDate() != null) { endDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getEndDate()); } else { endDate = this.messageReturn(null); } Paragraph cellContent; // Add content try { PdfPTable table = new PdfPTable(4); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 3, 5, 3, 5 }); // First row cellContent = new Paragraph(this.getText("summaries.project.startDate") + "\n" + " (dd-MM-yyyy)", TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); cellContent = new Paragraph(this.messageReturn(startDate), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); cellContent = new Paragraph(this.getText("summaries.project.endDate") + "\n" + " (dd-MM-yyyy)", TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); cellContent = new Paragraph(this.messageReturn(endDate), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); // Second row cellContent = new Paragraph(this.getText("summaries.project.managementLiaison"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); cellContent = new Paragraph(this.messageReturn(project.getLiaisonInstitution().getAcronym() + " - " + project.getLiaisonInstitution().getName()), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); cellContent = new Paragraph(this.getText("summaries.project.contactPerson"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); cellContent = new Paragraph(this.messageReturn(project.getOwner().getComposedName()), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); // Third row cellContent = new Paragraph(this.getText("summaries.project.leadOrganization"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); if (project.getLeader() == null || project.getLeader().getInstitution() == null) { cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } else { cellContent = new Paragraph( this.messageReturn( this.messageReturn(project.getLeader().getInstitution().getComposedName())), TABLE_BODY_FONT); } this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); cellContent = new Paragraph(this.getText("summaries.project.projectLeader"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); if (project.getLeaderPerson() == null || project.getLeaderPerson().getUser() == null) { cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } else { cellContent = new Paragraph( this.messageReturn(project.getLeaderPerson().getUser().getComposedName()), TABLE_BODY_FONT); } this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); // Fourth row cellContent = (new Paragraph(this.getText("summaries.project.projectType"), TABLE_BODY_BOLD_FONT)); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); cellContent = new Paragraph(this.messageReturn(project.getType().replaceAll("_", " ")), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); // Fiveth row Chunk imdb = null; Font hyperLink = new Font(FontFactory.getFont("openSans", 10, Color.BLUE)); hyperLink.setStyle(Font.UNDERLINE); // -- Not Bilateral if (!project.isBilateralProject()) { cellContent = (new Paragraph(this.getText("summaries.project.detailed"), TABLE_BODY_BOLD_FONT)); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); if (project.getWorkplanName() != null && !project.getWorkplanName().equals("")) { imdb = new Chunk(project.getWorkplanName(), hyperLink); try { imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL())))); } catch (MalformedURLException exp) { imdb = new Chunk(project.getWorkplanName(), TABLE_BODY_FONT); LOG.error("There is an Malformed exception in " + project.getWorkplanName()); } } else { imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } } // -- Bilateral else { cellContent = (new Paragraph(this.getText("summaries.project.ipContributions.proposal.space"), TABLE_BODY_BOLD_FONT)); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); if (project.getBilateralContractProposalName() != null && !project.getBilateralContractProposalName().equals("")) { imdb = new Chunk(project.getBilateralContractProposalName(), hyperLink); try { imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL())))); } catch (MalformedURLException exp) { imdb = new Chunk(project.getBilateralContractProposalName(), TABLE_BODY_FONT); LOG.error("There is an Malformed exception in bilateral contract: " + project.getBilateralContractProposalName()); } } else { imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } } cellContent = new Paragraph(); cellContent.add(imdb); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); document.add(table); document.add(Chunk.NEWLINE); } 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.CaseStudieSummaryPDF.java
License:Open Source License
/** * This method is used for add Outcomes in the project summary *//* w w w . ja v a2s . com*/ private void addProjectOutcomes(String number) { try { 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 (Exception e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } Anchor anchor; ////////////////// Reporting PdfPTable table; // ********************************************************************************** // *************************** Outcome Case Studies ************************************* // ********************************************************************************** if (project.isReporting()) { document.newPage(); Paragraph cell; 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); } List<Project> lst = projectManager.getAllProjectsBasicInfo(APConstants.REPORTING_SECTION); Collections.sort(lst, new Comparator<Project>() { @Override public int compare(Project s1, Project s2) { Integer p1 = s1.getId(); Integer p2 = s2.getId(); return p1.compareTo(p2); } }); for (Project project : lst) { project = projectManager.getProject(project.getId()); if (project.isWorkplanRequired()) { String workPlanURL = this.getWorkplanURL(); if (workPlanURL != null || project.getWorkplanName() != null) { project.setWorkplanURL(workPlanURL + project.getWorkplanName()); } } // Get a route for the bilateral contract if (project.isBilateralProject()) { String bilateralContractURL = this.getBilateralContractURL(); if (bilateralContractURL != null || project.getBilateralContractProposalName() != null) { project.setWorkplanURL( bilateralContractURL + project.getBilateralContractProposalName()); } } // Getting the information of the Regions program project.setRegions( ipProgramManager.getProjectFocuses(project.getId(), APConstants.REGION_PROGRAM_TYPE)); // Getting the information of the Flagships program project.setFlagships( ipProgramManager.getProjectFocuses(project.getId(), APConstants.FLAGSHIP_PROGRAM_TYPE)); List<ProjectPartner> projectPartnerList = this.partnerManager.getProjectPartners(project, 0); for (ProjectPartner projectPartner : projectPartnerList) { projectPartner .setPartnerPersons(this.partnerPersonManager.getPartnerPersons(projectPartner)); projectPartner.setPartnerContributors( partnerManager.getProjectPartnerContributors(projectPartner)); } project.setProjectPartners(projectPartnerList); this.project = project; List<CasesStudies> caseStudiesList = caseStudiesManager.getCaseStudysByProject(project.getId()); List<IPIndicator> ipIndicatorList; IPIndicator ipIndicator; if (caseStudiesList != null) { if (!caseStudiesList.isEmpty()) { try { this.addProjectTitle(); this.addMainInformationTable(); } catch (Exception e) { System.out.println(project.getId()); e.printStackTrace(); } } for (CasesStudies caseStudie : caseStudiesList) { ipIndicatorList = new ArrayList<IPIndicator>(); for (CaseStudieIndicators indicatorCaseStudie : caseStudie .getCaseStudieIndicatorses()) { ipIndicator = indicatorManager .getIndicatorFlgship(indicatorCaseStudie.getIdIndicator()); ipIndicatorList.add(ipIndicator); } caseStudie.setCaseStudyIndicators(ipIndicatorList); } project.setCaseStudies(caseStudiesList); int counter = 0; 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)); } } document.newPage(); } } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java
License:Open Source License
/** * Entering the project title in the summary *///from ww w. j a v a 2 s .c o m private void addProjectTitle() { LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -7); Paragraph paragraph = new Paragraph(); line.setLineColor(titleColor); try { paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.setFont(BODY_TEXT_BOLD_FONT); paragraph.add("Project: "); paragraph.setFont(BODY_TEXT_FONT); paragraph.add(this.messageReturn("P" + project.getId() + " - ")); paragraph.add(this.messageReturn(project.getTitle())); paragraph.add(line); document.add(paragraph); document.add(Chunk.NEWLINE); ; } 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.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * This method add Activities for the summary project *//*from ww w.j a v a2 s . c o m*/ private void addActivities() { try { document.newPage(); Paragraph activityBlock = new Paragraph("6. " + this.getText("summaries.project.activity"), HEADING2_FONT); activityBlock.setAlignment(Element.ALIGN_JUSTIFIED); activityBlock.add(Chunk.NEWLINE); PdfPTable table; List<Activity> listActivities = project.getActivities(); if (listActivities.isEmpty()) { activityBlock.setFont(BODY_TEXT_FONT); activityBlock.add(this.getText("summaries.project.empty")); document.add(activityBlock); } else { activityBlock.add(Chunk.NEWLINE); document.add(activityBlock); int counter = 1; for (Activity activity : listActivities) { boolean printActity = true; if (activity != null) { if (!project.isReporting()) { Calendar c = Calendar.getInstance(); c.setTime(activity.getEndDate()); Calendar cStartDate = Calendar.getInstance(); cStartDate.setTime(activity.getStartDate()); if (c.get(Calendar.YEAR) != config.getPlanningCurrentYear()) { if (cStartDate.get(Calendar.YEAR) != config.getPlanningCurrentYear()) { printActity = false; } } if (activity.getActivityStatus() == Integer .parseInt(ProjectStatusEnum.Cancelled.getStatusId())) { printActity = false; } } if (printActity) { table = new PdfPTable(2); table.setTotalWidth(480); table.setLockedWidth(true); // Header table activityBlock = new Paragraph(); activityBlock.setAlignment(Element.ALIGN_CENTER); activityBlock.setFont(TABLE_HEADER_FONT); activityBlock.add("Activity #" + counter); PdfPCell cell_new = new PdfPCell(activityBlock); cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND); cell_new.setUseBorderPadding(true); cell_new.setPadding(3); cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(2); this.addTableHeaderCell(table, cell_new); // Activity title activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.activities.title")); activityBlock.setFont(TABLE_BODY_FONT); activityBlock.add(this.messageReturn(activity.getTitle())); activityBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Activity description activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.activities.description")); activityBlock.setFont(TABLE_BODY_FONT); activityBlock.add(this.messageReturn(activity.getDescription())); activityBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2); String startDate = null; String endDate = null; try { startDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getStartDate()); } catch (Exception e) { } try { endDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getEndDate()); } catch (Exception e) { } // Activity Start Date activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.startDate") + " (dd-MM-yyyy)" + ": "); activityBlock.setFont(TABLE_BODY_FONT); activityBlock.add(startDate); activityBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1); // Activity End Date activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.endDate") + " (dd-MM-yyyy)" + ": "); activityBlock.setFont(TABLE_BODY_FONT); activityBlock.add(endDate); activityBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1); // Activity Leader activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.activities.activityLeader") + ": "); activityBlock.setFont(TABLE_BODY_FONT); PartnerPerson activityPartnerPerson = activity.getLeader(); if (activityPartnerPerson != null) { activityBlock.add(activityPartnerPerson.getComposedName()); String partnerInstitution = this.mapPartnerPersons .get(String.valueOf(activityPartnerPerson.getId())); if (partnerInstitution != null) { activityBlock.add(", " + partnerInstitution); } } else { activityBlock.add(this.getText("summaries.project.empty")); } activityBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2); // if (project.isReporting()) { // status activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.activities.status")); activityBlock.setFont(TABLE_BODY_FONT); if (activity.getActivityStatus() > 0) { activityBlock.add(statuses.get(String.valueOf(activity.getActivityStatus()))); } else { activityBlock.add(" " + this.getText("summaries.project.empty")); // } activityBlock.add(Chunk.NEWLINE); if (activity.isStatusCancelled() || activity.isStatusExtended() || activity.isStatusOnGoing()) { this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1); activityBlock = new Paragraph(); activityBlock.setFont(TABLE_BODY_BOLD_FONT); activityBlock.add(this.getText("summaries.project.activities.justification")); activityBlock.setFont(TABLE_BODY_FONT); activityBlock.add(this.messageReturn(activity.getActivityProgress())); activityBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1); } else { this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2); } } // document.add(Chunk.NEWLINE); document.add(table); activityBlock = new Paragraph(); activityBlock.add(Chunk.NEWLINE); document.add(activityBlock); counter++; } } } // Leason regardins activityBlock = new Paragraph(); activityBlock.setAlignment(Element.ALIGN_JUSTIFIED); activityBlock.setFont(BODY_TEXT_BOLD_FONT); if (!project.isReporting()) { activityBlock.add(this.getText("summaries.project.activities.lessonsRegarding")); } else { activityBlock.add(this.getText("summaries.project.activities.reporting.lessonsRegarding")); } activityBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("activities") != null) { activityBlock.add(this.messageReturn(project.getComponentLesson("activities").getLessons())); } else { activityBlock.add(this.messageReturn(null)); } document.add(activityBlock); } } catch (DocumentException e) { LOG.error( "There was an error trying to add the project activities to the project summary pdf of project {} ", e, project.getId()); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addBudgetReporting(String number) { try {/*w w w.j a v a 2 s . c o m*/ document.newPage(); Paragraph leverageBlock = new Paragraph( number + ". " + this.getText("summaries.project.leverage") + "s", HEADING2_FONT); leverageBlock.setAlignment(Element.ALIGN_JUSTIFIED); leverageBlock.add(Chunk.NEWLINE); PdfPTable table; List<ProjectLeverage> listLeverage = project.getLeverages(); if (listLeverage.isEmpty()) { leverageBlock.setFont(BODY_TEXT_FONT); leverageBlock.add(this.getText("summaries.project.empty")); document.add(leverageBlock); } else { leverageBlock.add(Chunk.NEWLINE); document.add(leverageBlock); int counter = 1; for (ProjectLeverage leverage : listLeverage) { if (leverage != null) { table = new PdfPTable(2); table.setTotalWidth(480); table.setLockedWidth(true); // Header table leverageBlock = new Paragraph(); leverageBlock.setAlignment(Element.ALIGN_CENTER); leverageBlock.setFont(TABLE_HEADER_FONT); leverageBlock.add(this.getText("summaries.project.leverage") + " #" + counter); this.addTableHeaderCellColspan(table, leverageBlock, 2); // leverage title leverageBlock = new Paragraph(); leverageBlock.setFont(TABLE_BODY_BOLD_FONT); leverageBlock.add(this.getText("summaries.project.activities.title")); leverageBlock.setFont(TABLE_BODY_FONT); leverageBlock.add(this.messageReturn(leverage.getTitle())); leverageBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Leverage institution leverageBlock = new Paragraph(); leverageBlock.setFont(TABLE_BODY_BOLD_FONT); leverageBlock.add(this.getText("summaries.project.leverage.partnerName")); leverageBlock.setFont(TABLE_BODY_FONT); if (leverage.getMyInstitution() != null) { leverageBlock.add(this.messageReturn(leverage.getMyInstitution().getComposedName())); } else { leverageBlock.add(this.messageReturn(null)); } leverageBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Leverage Year leverageBlock = new Paragraph(); leverageBlock.setFont(TABLE_BODY_BOLD_FONT); leverageBlock.add(this.getText("summaries.project.leverage.year")); leverageBlock.setFont(TABLE_BODY_FONT); leverageBlock.add(String.valueOf(this.currentReportingYear)); leverageBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Leverage Flagship leverageBlock = new Paragraph(); leverageBlock.setFont(TABLE_BODY_BOLD_FONT); leverageBlock.add(this.getText("summaries.project.leverage.flagship")); leverageBlock.setFont(TABLE_BODY_FONT); leverageBlock.add( this.messageReturn(String.valueOf(leverage.getMyFlagship().getComposedName()))); leverageBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1); // Leverage Budget leverageBlock = new Paragraph(); leverageBlock.setFont(TABLE_BODY_BOLD_FONT); leverageBlock.add(this.getText("summaries.project.leverage.budget")); leverageBlock.setFont(TABLE_BODY_FONT); if (leverage.getBudget() != null) { leverageBlock.add("US $"); leverageBlock.add(this.budgetFormatter.format(leverage.getBudget().doubleValue())); } else { leverageBlock.add(this.messageReturn(null)); } leverageBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1); document.add(table); leverageBlock = new Paragraph(); leverageBlock.add(Chunk.NEWLINE); document.add(leverageBlock); counter++; } } document.add(leverageBlock); } } catch (DocumentException e) { LOG.error( "There was an error trying to add the project activities to the project summary pdf of project {} ", e, project.getId()); } }
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 w w w .j a v a 2 s . 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); } }