List of usage examples for com.lowagie.text.pdf PdfPCell setPadding
public void setPadding(float padding)
From source file:optika.sql.java
public PdfPCell getCellWhite(String text, int alignment, int bottom) { PdfPCell cell = new PdfPCell(); FontSelector selector = new FontSelector(); com.lowagie.text.Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); f1.setColor(Color.white);/*from www . ja v a2s . c o m*/ selector.addFont(f1); cell.addElement(selector.process(text)); cell.setPadding(0); cell.setHorizontalAlignment(alignment); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingBottom(bottom); return cell; }
From source file:optika.sql.java
public PdfPCell getCell(String text, int alignment, int bottom) { PdfPCell cell = new PdfPCell(new Phrase(text)); cell.setPadding(0); cell.setHorizontalAlignment(alignment); cell.setBorder(PdfPCell.NO_BORDER);/*from w w w . j a v a 2 s . co m*/ cell.setPaddingBottom(bottom); return cell; }
From source file:org.areasy.common.doclet.document.Members.java
License:Open Source License
/** * Prints member information.// w w w. j a v a 2 s .c o m * * @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.ProjectSummaryPDF.java
License:Open Source License
/** * This method add Activities for the summary project *///from w ww . j a v a 2 s . com 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
/** * @param deliverable deliverable to add in the summary * @param counter number of deliverable// ww w .j av a2 s . com **/ private void addDelivable(Deliverable deliverable, int counter) { try { if (deliverable != null) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(480); table.setLockedWidth(true); StringBuilder stringBuilder = new StringBuilder(); PdfPCell cell_new; // **** Expected Deliverable #********* Paragraph deliverableBlock = new Paragraph(); deliverableBlock.setFont(HEADING4_FONT); if (project.isReporting()) { deliverableBlock.add(this.getText("summaries.project.deliverable") + " #" + counter); } else { if (deliverable.getYear() < config.getPlanningCurrentYear()) { deliverableBlock.add(this.getText("summaries.project.deliverable") + " #" + counter); } else { deliverableBlock .add(this.getText("summaries.project.deliverable.expected") + " #" + counter); } } deliverableBlock.add(Chunk.NEWLINE); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // **** Deliverable Information ********* deliverableBlock = new Paragraph(); deliverableBlock.setFont(BODY_TEXT_BOLD_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.information")); cell_new = new PdfPCell(deliverableBlock); 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); // Title deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.information.title") + ": "); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(this.messageReturn(deliverable.getTitle())); deliverableBlock.add(Chunk.NEWLINE); ; // document.add(deliverableBlock); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); // MOG deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); if (deliverable.getOutput() != null) { stringBuilder = new StringBuilder(); if (deliverable.getOutput().getProgram() != null && deliverable.getOutput().getProgram().getAcronym() != null) { stringBuilder.append(deliverable.getOutput().getProgram().getAcronym()); stringBuilder.append(" - MOG # "); } else { stringBuilder.append("MOG # "); } stringBuilder.append(this.getMOGIndex(deliverable.getOutput())); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); stringBuilder.append(deliverable.getOutput().getDescription()); } else { deliverableBlock.add("MOG :"); stringBuilder.append(this.getText("summaries.project.empty")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); // document.add(deliverableBlock); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Main Type deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.main")); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); if (deliverable.getType() != null && deliverable.getType().getCategory() != null) { stringBuilder.append(this.messageReturn(deliverable.getType().getCategory().getName())); } else { stringBuilder.append(this.messageReturn("")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); // Sub Type deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.sub")); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); if (deliverable.getType() == null) { stringBuilder.append(this.messageReturn(this.getText("summaries.project.empty"))); } else if (deliverable.getType().getId() == 38) { stringBuilder.append(this.getText("summaries.project.deliverable.other.expected")); stringBuilder.append("("); stringBuilder.append(this.messageReturn(deliverable.getTypeOther())); stringBuilder.append(")"); } else { stringBuilder.append(this.messageReturn(deliverable.getType().getName())); } deliverableBlock.add(this.messageReturn(stringBuilder.toString())); deliverableBlock.add(Chunk.NEWLINE); ; // document.add(deliverableBlock); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Year deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.year")); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); stringBuilder.append(deliverable.getYear()); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); // document.add(deliverableBlock); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Status deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.statuts")); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); if (deliverable.getStatus() != 0) { if (deliverable.getStatus() == Integer.parseInt(ProjectStatusEnum.Cancelled.getStatusId())) { deliverableBlock.setFont(TABLE_BODY_FONT_RED); } stringBuilder.append(this.statuses.get(String.valueOf(deliverable.getStatus()))); } else { stringBuilder.append(this.messageReturn(null)); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); // document.add(deliverableBlock); if (deliverable.isStatusCancelled() || deliverable.isStatusExtended() || deliverable.isStatusOnGoing()) { this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 1); // Justification deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.justification")); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(this.messageReturn(deliverable.getStatusDescription())); deliverableBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 1); } else { this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); } document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Next Users************************************** counter = 1; List<NextUser> nextUsers = deliverable.getNextUsers(); for (NextUser nextUser : nextUsers) { if (nextUser != null) { table = new PdfPTable(1); table.setTotalWidth(480); table.setLockedWidth(true); // Next user title deliverableBlock = new Paragraph(); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(TABLE_HEADER_FONT); if (nextUsers.size() == 1) { deliverableBlock.add(this.getText("summaries.project.deliverable.next.user")); } else { deliverableBlock .add(this.getText("summaries.project.deliverable.next.user") + " #" + counter); } this.addTableHeaderCell(table, deliverableBlock); // Next user stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder.append(nextUser.getUser()); deliverableBlock.add(this.messageReturn(stringBuilder.toString())); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); // Expected Changes stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock .add(this.getText("summaries.project.deliverable.next.user.expected.change")); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder.append(this.messageReturn(nextUser.getExpectedChanges())); deliverableBlock.add(stringBuilder.toString()); // document.add(deliverableBlock); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); // Strategies stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.next.user.strategies")); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder.append(this.messageReturn(nextUser.getStrategies())); deliverableBlock.add(stringBuilder.toString()); // document.add(deliverableBlock); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); counter++; } } // ********** Deliverable partnership**************************** // ******************Partner contributing counter = 1; table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); // Title partners contributing deliverableBlock = new Paragraph(); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.partnership")); deliverableBlock.setFont(TABLE_HEADER_FONT); this.addTableHeaderCell(table, deliverableBlock); // Organization stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.partnership.organization") + " #" + counter + " (Responsible)" + ": "); deliverableBlock.setFont(TABLE_BODY_FONT); DeliverablePartner deliverableResponsiblePartner = deliverable.getResponsiblePartner(); PartnerPerson partnerPersonResponsible = null; if (deliverableResponsiblePartner != null) { partnerPersonResponsible = deliverableResponsiblePartner.getPartner(); } if (deliverableResponsiblePartner != null && partnerPersonResponsible != null) { stringBuilder.append(this.messageReturn(partnerPersonResponsible.getComposedName())); stringBuilder.append(", "); stringBuilder .append(this.mapPartnerPersons.get(String.valueOf(partnerPersonResponsible.getId()))); } else { stringBuilder.append(this.getText("summaries.project.empty")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); ; this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); counter = 1; // ************** Other Partners List<DeliverablePartner> listOtherPartner = deliverable.getOtherPartners(); PartnerPerson otherResponsiblepartnerPerson = null; if (!listOtherPartner.isEmpty()) { for (DeliverablePartner deliverablePartner : listOtherPartner) { if (deliverablePartner != null) { counter++; // Title partners contributing deliverableBlock = new Paragraph(); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(BODY_TEXT_BOLD_FONT); if (listOtherPartner.size() == 1) { deliverableBlock.add(this.getText("summaries.project.deliverable.partnership")); } else { deliverableBlock.add( this.getText("summaries.project.deliverable.partnership") + " #" + counter); } // Organization stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock .add(this.getText("summaries.project.deliverable.partnership.organization") + " #" + counter + ": "); deliverableBlock.add(""); deliverableBlock.setFont(TABLE_BODY_FONT); otherResponsiblepartnerPerson = deliverablePartner.getPartner(); if (otherResponsiblepartnerPerson != null) { stringBuilder.append( this.messageReturn(otherResponsiblepartnerPerson.getComposedName())); stringBuilder.append(", "); stringBuilder.append(this.mapPartnerPersons .get(String.valueOf(otherResponsiblepartnerPerson.getId()))); } else { stringBuilder.append(this.getText("summaries.project.empty")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); ; this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); } } } document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); } // ********** Ranking************************************** PdfPCell cell_new; if (project.isReporting()) { PdfPTable table = new PdfPTable(2); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 7, 3 }); DeliverablesRanking deliverableRanking = deliverable.getRanking(); // summaries.project.reporting.deliverable.ranking Paragraph deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.ranking")); cell_new = new PdfPCell(deliverableBlock); 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); // address gender deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.addres.gender")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getAddress() != null) { deliverableBlock.add(this.messageReturn(deliverableRanking.getAddress().toString())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); // Get Potential deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.contribution.outcome")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getPotential() != null) { deliverableBlock.add(this.messageReturn(deliverableRanking.getPotential().toString())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); // Level deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.shared.ownership")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getLevel() != null) { deliverableBlock.add(this.messageReturn(deliverableRanking.getLevel().toString())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); // Personal perspective deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.personal.prespective")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getPersonalPerspective() != null) { deliverableBlock .add(this.messageReturn(String.valueOf(deliverableRanking.getPersonalPerspective()))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Deliverable Dissemination************************************** DeliverableDissemination deliverableDissemination = deliverable.getDissemination(); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination")); this.addTableHeaderCell(table, deliverableBlock); // Open access deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.open")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableDissemination != null) { if (deliverableDissemination.getIsOpenAccess() != null && deliverableDissemination.getIsOpenAccess().booleanValue()) { deliverableBlock.add("Yes"); } else if (deliverableDissemination.getIntellectualProperty() != null && deliverableDissemination.getIntellectualProperty().booleanValue()) { deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.intellectual")); } else if (deliverableDissemination.getLimitedExclusivity() != null && deliverableDissemination.getLimitedExclusivity().booleanValue()) { deliverableBlock .add(this.getText("summaries.project.reporting.deliverable.dissemination.limited")); } else if (deliverableDissemination.getRestrictedUseAgreement() != null && deliverableDissemination.getRestrictedUseAgreement().booleanValue()) { deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.restricted")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock .add(this.getText("summaries.project.reporting.deliverable.dissemination.access")); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(deliverableDissemination.getRestrictedAccessUntilText()); } else if (deliverableDissemination.getEffectiveDateRestriction() != null && deliverableDissemination.getEffectiveDateRestriction().booleanValue()) { deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.effective")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.embargoed")); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(deliverableDissemination.getRestrictedEmbargoedText()); } else { deliverableBlock.add(this.messageReturn(null)); } } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // License adopted deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.license")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableDissemination != null) { if (deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_LICENSE) != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_LICENSE))); } else { deliverableBlock.add("No"); } } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // // Dissemination channel deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.channel")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableDissemination != null) { deliverableBlock.add(this.messageReturn(deliverableDissemination.getDisseminationChannel())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Dissemination URL deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.url")); deliverableBlock.setFont(TABLE_BODY_FONT_LINK); if (deliverableDissemination != null) { deliverableBlock.add(this.messageReturn(deliverableDissemination.getDisseminationUrl())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Deliverable Metadata************************************** DeliverablePublicationMetadata deliverableMetadata = deliverable.getPublicationMetadata(); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata")); this.addTableHeaderCell(table, deliverableBlock); // Description deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.description")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_DESCRIPTION))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // creator deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.creator")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn( deliverable.getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_CREATOR))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // authorID deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.authorID")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_CREATOR_ID))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Creation deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.creation")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_PUBLICATION))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Language deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.language")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_LANGUAGE)))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Coverage deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.coverage")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_COVERAGE))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Deliverable Data Sharing************************************** table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.datasharing")); this.addTableHeaderCell(table, deliverableBlock); // Files deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.datasharing.files")); deliverableBlock.add("\n"); deliverableBlock.setFont(TABLE_BODY_FONT); List<DeliverableDataSharingFile> deliverableDataSharingFileList = deliverable.getDataSharingFile(); cell_new = new PdfPCell(deliverableBlock); cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_BODY_ODD_ROW_BACKGROUND); cell_new.setUseBorderPadding(true); cell_new.setPadding(3); cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(2); Anchor anchor; Phrase myurl; counter = 0; if (deliverableDataSharingFileList != null) { for (DeliverableDataSharingFile deliverableDataSharingFile : deliverableDataSharingFileList) { if (deliverableDataSharingFile != null) { anchor = new Anchor(deliverableDataSharingFile.getFile(), TABLE_BODY_FONT_LINK); anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId() + "/deliverableDataSharing/" + deliverableDataSharingFile.getFile()); myurl = new Phrase(); myurl.add(anchor); myurl.setFont(TABLE_BODY_FONT_LINK); cell_new.addElement(myurl); if (counter > 1) { cell_new.addElement(new Paragraph("\n")); } counter++; } } table.addCell(cell_new); } else { deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(this.messageReturn(null)); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); } document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); } } catch (DocumentException e) { LOG.error( "-- generatePdf() > There was an error adding the table with content for case study summary. ", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addProjectCCAFSOutcomes(String number) { PdfPTable table = new PdfPTable(3); Paragraph cell = new Paragraph(); Paragraph indicatorsBlock = new Paragraph(); indicatorsBlock.setAlignment(Element.ALIGN_JUSTIFIED); indicatorsBlock.setKeepTogether(true); Paragraph title = new Paragraph(number + ".2 " + this.getText("summaries.project.indicatorsContribution"), HEADING3_FONT);/*from w w w . j a v a 2 s . c o m*/ indicatorsBlock.add(Chunk.NEWLINE); indicatorsBlock.add(title); try { document.add(indicatorsBlock); List<IPElement> listIPElements = this.getMidOutcomesPerIndicators(); if (!listIPElements.isEmpty()) { if (project.isReporting()) { for (IPElement outcome : listIPElements) { Paragraph outcomeBlock = new Paragraph(); int indicatorIndex = 1; outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomeBlock.setFont(BODY_TEXT_BOLD_FONT); outcomeBlock.add(outcome.getProgram().getAcronym()); outcomeBlock.add(" - " + this.getText("summaries.project.midoutcome")); outcomeBlock.setFont(BODY_TEXT_FONT); outcomeBlock.add(outcome.getDescription()); outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.add(Chunk.NEWLINE); document.add(outcomeBlock); for (IPIndicator outcomeIndicator : outcome.getIndicators()) { outcomeIndicator = outcomeIndicator.getParent() != null ? outcomeIndicator.getParent() : outcomeIndicator; List<IPIndicator> indicators = project.getIndicatorsByParent(outcomeIndicator.getId()); if (indicators.isEmpty()) { continue; } Paragraph indicatorDescription = new Paragraph(); indicatorDescription.setFont(BODY_TEXT_BOLD_FONT); indicatorDescription.add(this.getText("summaries.project.indicators")); indicatorDescription.add(String.valueOf(indicatorIndex) + ": "); indicatorDescription.setFont(BODY_TEXT_FONT); indicatorDescription.setAlignment(Element.ALIGN_JUSTIFIED); indicatorDescription.add(outcomeIndicator.getDescription()); document.add(indicatorDescription); document.add(Chunk.NEWLINE); ; PdfPCell cell_new; for (IPIndicator indicator : indicators) { table = new PdfPTable(3); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 3, 3, 3 }); table.setHeaderRows(1); if (indicator.getOutcome().getId() != outcome.getId()) { continue; } cell = new Paragraph(this.messageReturn(String.valueOf(indicator.getYear())), TABLE_HEADER_FONT); cell_new = new PdfPCell(cell); // Set alignment cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND); // Set padding cell_new.setUseBorderPadding(true); cell_new.setPadding(3); // Set border color cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(3); this.addTableHeaderCell(table, cell_new); // Target value cell = new Paragraph(this.getText("summaries.project.indicator.targetValue"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getTarget())); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); // Cumulative target to date // TODO cell = new Paragraph(this.getText("summaries.project.indicator.cumulative"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn( project.calculateAcumulativeTarget(indicator.getYear(), indicator))); if (indicator.getYear() <= this.currentReportingYear) { this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); // achieved cell = new Paragraph(this.getText("summaries.project.indicator.archieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); if (indicator.getArchived() == null) { cell.add(this.messageReturn(null)); } else { cell.add(this.messageReturn(String.valueOf(indicator.getArchived()))); } this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } else { this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 2); } // target narrative cell = new Paragraph(this.getText("summaries.project.indicator.targetNarrative"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getDescription())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); // targets achieved if (indicator.getYear() <= this.currentReportingYear) { cell = new Paragraph( this.getText("summaries.project.indicator.targetsAchieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getNarrativeTargets())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); } // Target gender cell = new Paragraph(this.getText("summaries.project.indicator.targetGender"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getGender())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); // Target achieved gender if (indicator.getYear() <= this.currentReportingYear) { cell = new Paragraph(this.getText("summaries.project.indicator.genderAchieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getNarrativeGender())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); } document.add(table); document.add(Chunk.NEWLINE); } indicatorIndex++; } } //////////// Planning } else { for (IPElement outcome : listIPElements) { Paragraph outcomeBlock = new Paragraph(); int indicatorIndex = 1; outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomeBlock.setFont(BODY_TEXT_BOLD_FONT); outcomeBlock.add(outcome.getProgram().getAcronym()); outcomeBlock.add(" - " + this.getText("summaries.project.midoutcome")); outcomeBlock.setFont(BODY_TEXT_FONT); outcomeBlock.add(outcome.getDescription()); outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.add(Chunk.NEWLINE); document.add(outcomeBlock); for (IPIndicator outcomeIndicator : outcome.getIndicators()) { outcomeIndicator = outcomeIndicator.getParent() != null ? outcomeIndicator.getParent() : outcomeIndicator; List<IPIndicator> indicators = project.getIndicatorsByParent(outcomeIndicator.getId()); if (indicators.isEmpty()) { continue; } Paragraph indicatorDescription = new Paragraph(); indicatorDescription.setFont(BODY_TEXT_BOLD_FONT); indicatorDescription.add(this.getText("summaries.project.indicators")); indicatorDescription.add(String.valueOf(indicatorIndex) + ": "); indicatorDescription.setFont(BODY_TEXT_FONT); indicatorDescription.setAlignment(Element.ALIGN_JUSTIFIED); indicatorDescription.add(outcomeIndicator.getDescription()); document.add(indicatorDescription); document.add(Chunk.NEWLINE); ; table = new PdfPTable(4); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 1, 3, 3, 3 }); table.setHeaderRows(1); // Headers cell = new Paragraph(this.getText("summaries.project.indicator.year"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetValue"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetNarrative"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetGender"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); for (IPIndicator indicator : indicators) { if (indicator.getOutcome().getId() != outcome.getId()) { continue; } cell = new Paragraph(this.messageReturn(String.valueOf(indicator.getYear())), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(this.messageReturn(indicator.getTarget()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(this.messageReturn(indicator.getDescription()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(this.messageReturn(indicator.getGender()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } indicatorIndex++; document.add(table); document.add(Chunk.NEWLINE); } } } // When there isn't elements in indicators } else { cell = new Paragraph(this.getText("summaries.project.empty")); document.add(cell); } } catch ( DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
@Override public void export(GTDModel model, ActionsCollection collection, OutputStream out, ExportAddOn.ExportOrder order, FileFilter ff, boolean compact) throws Exception { fontSelector = new FontSelector(); fontSelectorB = new FontSelector(); fontSelectorB2 = new FontSelector(); fontSelectorB4 = new FontSelector(); baseFont = fontModel.getBaseFont();//w w w .j a v a 2s . com for (BaseFont bf : fontModel.getFonts()) { fontSelector.addFont(new Font(bf, baseFontSize)); fontSelectorB.addFont(new Font(bf, baseFontSize, Font.BOLD)); fontSelectorB2.addFont(new Font(bf, baseFontSize + 2, Font.BOLD)); fontSelectorB4.addFont(new Font(bf, baseFontSize + 4, Font.BOLD)); } boolean emptyH2 = false; boolean emptyH3 = false; PdfPTable actionTable = null; Document doc = new Document(); if (sizeSet) { doc.setPageSize(pageSize); } if (marginSet) { doc.setMargins(marginLeft, marginRight, marginTop, marginBottom); } //System.out.println("PDF size "+doc.getPageSize().toString()); //System.out.println("PDF m "+marginLeft+" "+marginRight+" "+marginTop+" "+marginBottom); @SuppressWarnings("unused") PdfWriter pw = PdfWriter.getInstance(doc, out); doc.addCreationDate(); doc.addTitle("GTD-Free PDF"); doc.addSubject("GTD-Free data exported as PDF"); HeaderFooter footer = new HeaderFooter(newParagraph(), true); footer.setAlignment(HeaderFooter.ALIGN_CENTER); footer.setBorder(HeaderFooter.TOP); doc.setFooter(footer); doc.open(); Phrase ch = newTitle("GTD-Free Data"); Paragraph p = new Paragraph(ch); p.setAlignment(Paragraph.ALIGN_CENTER); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); PdfPCell c = newCell(p); c.setBorder(Table.BOTTOM); c.setBorderWidth(2.5f); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5f); t.addCell(c); doc.add(t); Iterator<Object> it = collection.iterator(order); while (it.hasNext()) { Object o = it.next(); if (o == ActionsCollection.ACTIONS_WITHOUT_PROJECT) { if (order == ExportAddOn.ExportOrder.FoldersProjectsActions) { doc.add(newSubSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT)); emptyH2 = false; emptyH3 = true; } else { doc.add(newSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT)); emptyH2 = true; emptyH3 = false; } continue; } if (o instanceof Folder) { Folder f = (Folder) o; if (actionTable != null) { doc.add(actionTable); actionTable = null; } if (f.isProject()) { if (order == ExportAddOn.ExportOrder.ProjectsActions || order == ExportAddOn.ExportOrder.ProjectsFoldersActions) { if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSection(f.getName())); if (compact) { if (f.getDescription() != null && f.getDescription().length() > 0) { p = newParagraph(f.getDescription()); p.setIndentationLeft(10f); p.setIndentationRight(10f); doc.add(p); } } else { t = new PdfPTable(2); t.setKeepTogether(true); t.setSpacingBefore(5f); t.setWidthPercentage(66f); t.setWidths(new float[] { 0.33f, 0.66f }); c = newCell("ID"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getId()))); t.addCell(c); c = newCell("Type"); t.addCell(c); c = newCell(newStrongParagraph("Project")); t.addCell(c); c = newCell("Open"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount()))); t.addCell(c); c = newCell("All"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.size()))); t.addCell(c); c = newCell("Description"); t.addCell(c); c = newDescriptionCell(f.getDescription()); t.addCell(c); doc.add(t); } emptyH2 = true; emptyH3 = false; } else { if (emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSubSection("Project:" + " " + f.getName())); emptyH2 = false; emptyH3 = true; } continue; } if (order == ExportAddOn.ExportOrder.FoldersActions || order == ExportAddOn.ExportOrder.FoldersProjectsActions) { if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSection(f.getName())); if (compact) { if (f.getDescription() != null && f.getDescription().length() > 0) { p = newParagraph(f.getDescription()); p.setIndentationLeft(10f); p.setIndentationRight(10f); doc.add(p); } } else { t = new PdfPTable(2); t.setKeepTogether(true); t.setSpacingBefore(5f); t.setWidthPercentage(66f); t.setWidths(new float[] { 0.33f, 0.66f }); c = newCell("ID"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getId()))); t.addCell(c); String type = ""; if (f.isAction()) { type = "Action list"; } else if (f.isInBucket()) { type = "In-Bucket"; } else if (f.isQueue()) { type = "Next action queue"; } else if (f.isReference()) { type = "Reference list"; } else if (f.isSomeday()) { type = "Someday/Maybe list"; } else if (f.isBuildIn()) { type = "Default list"; } c = newCell("Type"); t.addCell(c); c = newCell(newStrongParagraph(type)); t.addCell(c); c = newCell("Open"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount()))); t.addCell(c); c = newCell("All"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.size()))); t.addCell(c); c = newCell("Description"); t.addCell(c); c = newDescriptionCell(f.getDescription()); t.addCell(c); doc.add(t); } emptyH2 = true; emptyH3 = false; } else { if (emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSubSection("List:" + " " + f.getName())); emptyH2 = false; emptyH3 = true; } continue; } if (o instanceof Action) { emptyH2 = false; emptyH3 = false; Action a = (Action) o; if (compact) { if (actionTable == null) { actionTable = new PdfPTable(5); actionTable.setWidthPercentage(100f); actionTable.setHeaderRows(1); actionTable.setSpacingBefore(5f); c = newHeaderCell("ID"); actionTable.addCell(c); c = newHeaderCell("Pri."); actionTable.addCell(c); c = newHeaderCell("Description"); actionTable.addCell(c); c = newHeaderCell("Reminder"); actionTable.addCell(c); c = newHeaderCell(CHECK_RESOLVED); actionTable.addCell(c); float width = doc.getPageSize().getWidth() - doc.getPageSize().getBorderWidthLeft() - doc.getPageSize().getBorderWidthRight(); int i = model.getLastActionID(); float step = baseFontSize - 1; int steps = (int) Math.floor(Math.log10(i)) + 1; // ID column float col1 = 8 + steps * step; // Priority column float col2 = 4 + 3 * (baseFontSize + 4); // Reminder column float col4 = 10 + step * 11; // Resolved column float col5 = 8 + baseFontSize; // Description column float col3 = width - col1 - col2 - col4 - col5; actionTable.setWidths(new float[] { col1, col2, col3, col4, col5 }); } addSingleActionRow(a, actionTable); } else { addSingleActionTable(model, doc, a); } } } if (actionTable != null) { doc.add(actionTable); actionTable = null; } if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } //w.writeCharacters("Exported: "+ApplicationHelper.toISODateTimeString(new Date())); doc.close(); }
From source file:org.jmesa.view.pdfp.PdfPView.java
License:Apache License
@Override public PdfPTable render() { PdfPTable pdfpTable = new PdfPTable(getTable().getRow().getColumns().size()); pdfpTable.setSpacingBefore(3);//from w ww . ja v a2 s . c o m Row row = getTable().getRow(); List<Column> columns = row.getColumns(); // build table headers for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { Column column = iter.next(); PdfPCell cell = new PdfPCell(new Paragraph(column.getTitle(), getHeaderCellFont())); cell.setPadding(3.0f); cell.setBackgroundColor(getHeaderBackgroundColor()); pdfpTable.addCell(cell); } // build table body Collection<?> items = getCoreContext().getPageItems(); int rowcount = 0; for (Object item : items) { rowcount++; columns = row.getColumns(); for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { Column column = iter.next(); String property = column.getProperty(); Object value = column.getCellEditor().getValue(item, property, rowcount); PdfPCell cell = new PdfPCell( new Paragraph(value == null ? "" : String.valueOf(value), getCellFont())); cell.setPadding(3.0f); if (isRowEven(rowcount)) { cell.setBackgroundColor(getEvenCellBackgroundColor()); } else { cell.setBackgroundColor(getOddCellBackgroundColor()); } pdfpTable.addCell(cell); } } return pdfpTable; }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsInvoiceReportServiceImpl.java
License:Open Source License
/** * this method generated the actual pdf for the Contracts & Grants LOC Review Document. * * @param os// ww w.ja v a 2s . c om * @param LOCDocument */ protected void generateLOCReviewInPdf(OutputStream os, ContractsGrantsLetterOfCreditReviewDocument locDocument) { try { Document document = new Document( new Rectangle(ArConstants.LOCReviewPdf.LENGTH, ArConstants.LOCReviewPdf.WIDTH)); PdfWriter.getInstance(document, os); document.open(); Paragraph header = new Paragraph(); Paragraph text = new Paragraph(); Paragraph title = new Paragraph(); // Lets write the header header.add(new Paragraph(configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_TITLE), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); if (StringUtils.isNotEmpty(locDocument.getLetterOfCreditFundGroupCode())) { header.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_FUND_GROUP_CODE) + locDocument.getLetterOfCreditFundGroupCode(), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); } if (StringUtils.isNotEmpty(locDocument.getLetterOfCreditFundCode())) { header.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_FUND_CODE) + locDocument.getLetterOfCreditFundCode(), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); } header.add(new Paragraph(KFSConstants.BLANK_SPACE)); header.setAlignment(Element.ALIGN_CENTER); title.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_NUMBER) + locDocument.getDocumentNumber(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); Person person = getPersonService() .getPerson(locDocument.getFinancialSystemDocumentHeader().getInitiatorPrincipalId()); // writing the Document details title.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_APP_DOC_STATUS) + locDocument.getFinancialSystemDocumentHeader().getApplicationDocumentStatus(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add( new Paragraph( configService.getPropertyValueAsString( ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_INITIATOR) + person.getName(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add(new Paragraph( configService .getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_CREATE_DATE) + getDateTimeService().toDateString( locDocument.getFinancialSystemDocumentHeader().getWorkflowCreateDate()), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add(new Paragraph(KFSConstants.BLANK_SPACE)); title.setAlignment(Element.ALIGN_RIGHT); text.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_SUBHEADER_AWARDS), ArConstants.PdfReportFonts.LOC_REVIEW_SMALL_BOLD)); text.add(new Paragraph(KFSConstants.BLANK_SPACE)); document.add(header); document.add(title); document.add(text); PdfPTable table = new PdfPTable(11); table.setTotalWidth(ArConstants.LOCReviewPdf.RESULTS_TABLE_WIDTH); // fix the absolute width of the table table.setLockedWidth(true); // relative col widths in proportions - 1/11 float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; table.setWidths(widths); table.setHorizontalAlignment(0); addAwardHeaders(table); if (CollectionUtils.isNotEmpty(locDocument.getHeaderReviewDetails()) && CollectionUtils.isNotEmpty(locDocument.getAccountReviewDetails())) { for (ContractsGrantsLetterOfCreditReviewDetail item : locDocument.getHeaderReviewDetails()) { table.addCell(Long.toString(item.getProposalNumber())); table.addCell(item.getAwardDocumentNumber()); table.addCell(item.getAgencyNumber()); table.addCell(item.getCustomerNumber()); table.addCell(getDateTimeService().toDateString(item.getAwardBeginningDate())); table.addCell(getDateTimeService().toDateString(item.getAwardEndingDate())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getAwardBudgetAmount())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getLetterOfCreditAmount())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getClaimOnCashBalance())); table.addCell(contractsGrantsBillingUtilityService.formatForCurrency(item.getAmountToDraw())); table.addCell(contractsGrantsBillingUtilityService .formatForCurrency(item.getAmountAvailableToDraw())); PdfPCell cell = new PdfPCell(); cell.setPadding(ArConstants.LOCReviewPdf.RESULTS_TABLE_CELL_PADDING); cell.setColspan(ArConstants.LOCReviewPdf.RESULTS_TABLE_COLSPAN); PdfPTable newTable = new PdfPTable(ArConstants.LOCReviewPdf.INNER_TABLE_COLUMNS); newTable.setTotalWidth(ArConstants.LOCReviewPdf.INNER_TABLE_WIDTH); // fix the absolute width of the newTable newTable.setLockedWidth(true); // relative col widths in proportions - 1/8 float[] newWidths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; newTable.setWidths(newWidths); newTable.setHorizontalAlignment(0); addAccountsHeaders(newTable); for (ContractsGrantsLetterOfCreditReviewDetail newItem : locDocument .getAccountReviewDetails()) { if (item.getProposalNumber().equals(newItem.getProposalNumber())) { newTable.addCell(newItem.getAccountDescription()); newTable.addCell(newItem.getChartOfAccountsCode()); newTable.addCell(newItem.getAccountNumber()); String accountExpirationDate = KFSConstants.EMPTY_STRING; if (!ObjectUtils.isNull(newItem.getAccountExpirationDate())) { accountExpirationDate = getDateTimeService() .toDateString(newItem.getAccountExpirationDate()); } newTable.addCell(accountExpirationDate); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getAwardBudgetAmount())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getClaimOnCashBalance())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getAmountToDraw())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getFundsNotDrawn())); } } cell.addElement(newTable); table.addCell(cell); } document.add(table); } document.close(); } catch (DocumentException e) { LOG.error("problem during ContractsGrantsInvoiceReportServiceImpl.generateInvoiceInPdf()", e); } }
From source file:org.mapfish.print.config.layout.LegendsBlock.java
License:Open Source License
private PdfPCell createLine(RenderingContext context, double indent, PJsonObject node, Font pdfFont, PJsonObject params) throws DocumentException { final String name = node.getString("name"); final String icon = node.optString("icon"); final PJsonArray icons = node.optJSONArray("icons"); final Paragraph result = new Paragraph(); result.setFont(pdfFont);//w ww . java 2s. c om if (icon != null) { result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(icon), 0.0f)); result.add(" "); } if (icons != null) { for (int i = 0; i < icons.size(); ++i) { String iconItem = icons.getString(i); try { result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(iconItem), 0.0f)); result.add(" "); } catch (InvalidValueException e) { LOGGER.warn("Failed to create image chunk: " + e.getMessage()); } } } result.add(name); final PdfPCell cell = new PdfPCell(result); cell.setBorder(PdfPCell.NO_BORDER); cell.setPadding(0f); cell.setPaddingLeft((float) indent); if (getBackgroundColorVal(context, params) != null) { cell.setBackgroundColor(getBackgroundColorVal(context, params)); } return cell; }