List of usage examples for com.lowagie.text Phrase Phrase
public Phrase()
Phrase
without specifying a leading. From source file:mitm.common.pdf.MessagePDFBuilder.java
License:Open Source License
private void addReplyLink(Document document, String replyURL) throws DocumentException { PdfPTable replyTable = new PdfPTable(1); replyTable.setWidthPercentage(100f); replyTable.setSplitLate(false);//w w w . ja v a 2 s .co m replyTable.setSpacingBefore(5f); replyTable.setHorizontalAlignment(Element.ALIGN_LEFT); Font linkFont = new Font(); linkFont.setStyle(Font.BOLD); linkFont.setColor(0, 0, 255); linkFont.setSize(headerFontSize); Chunk anchor = new Chunk("Reply", linkFont); anchor.setAnchor(replyURL); Phrase phrase = new Phrase(); phrase.add(anchor); PdfPCell cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); replyTable.addCell(cell); document.add(replyTable); }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
License:LGPL
/** * *//* w w w .jav a 2 s. c o m*/ protected Phrase getPhrase(JRStyledText styledText, JRPrintText textElement) { Phrase phrase = new Phrase(); String text = styledText.getText(); int runLimit = 0; AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator(); while (runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) { Chunk chunk = getChunk(iterator.getAttributes(), text.substring(iterator.getIndex(), runLimit)); setAnchor(chunk, textElement, textElement); setHyperlinkInfo(chunk, textElement); phrase.add(chunk); iterator.setIndex(runLimit); } return phrase; }
From source file:nl.knaw.dans.common.lang.pdf.ExtendedHtmlWorker.java
License:Apache License
public void endElement(String tag) { if (!tagsSupported.containsKey(tag)) return;//from w ww . j a v a2s . c o m try { String follow = (String) FactoryProperties.followTags.get(tag); if (follow != null) { cprops.removeChain(follow); return; } if (tag.equals("font") || tag.equals("span")) { cprops.removeChain(tag); return; } if (tag.equals("a")) { if (currentParagraph == null) currentParagraph = new Paragraph(); ALink i = null; boolean skip = false; if (interfaceProps != null) { i = (ALink) interfaceProps.get("alink_interface"); if (i != null) skip = i.process(currentParagraph, cprops); } if (!skip) { String href = cprops.getProperty("href"); if (href != null) { ArrayList chunks = currentParagraph.getChunks(); for (int k = 0; k < chunks.size(); ++k) { Chunk ck = (Chunk) chunks.get(k); ck.setAnchor(href); } } } Paragraph tmp = (Paragraph) stack.pop(); Phrase tmp2 = new Phrase(); tmp2.add(currentParagraph); tmp.add(tmp2); currentParagraph = tmp; cprops.removeChain("a"); return; } if (tag.equals("br")) { return; } if (currentParagraph != null) { if (stack.empty()) document.add(currentParagraph); else { Object obj = stack.pop(); if (obj instanceof TextElementArray) { TextElementArray current = (TextElementArray) obj; current.add(currentParagraph); } stack.push(obj); } } currentParagraph = null; if (tag.equals("ul") || tag.equals("ol")) { if (pendingLI) endElement("li"); skipText = false; cprops.removeChain(tag); if (stack.empty()) return; Object obj = stack.pop(); if (!(obj instanceof com.lowagie.text.List)) { stack.push(obj); return; } if (stack.empty()) document.add((Element) obj); else ((TextElementArray) stack.peek()).add(obj); return; } if (tag.equals("li")) { pendingLI = false; skipText = true; cprops.removeChain(tag); if (stack.empty()) return; Object obj = stack.pop(); if (!(obj instanceof ListItem)) { stack.push(obj); return; } if (stack.empty()) { document.add((Element) obj); return; } Object list = stack.pop(); if (!(list instanceof com.lowagie.text.List)) { stack.push(list); return; } ListItem item = (ListItem) obj; ((com.lowagie.text.List) list).add(item); ArrayList cks = item.getChunks(); if (!cks.isEmpty()) item.getListSymbol().setFont(((Chunk) cks.get(0)).getFont()); stack.push(list); return; } if (tag.equals("div") || tag.equals("body")) { cprops.removeChain(tag); return; } if (tag.equals("pre")) { cprops.removeChain(tag); isPRE = false; return; } if (tag.equals("p")) { cprops.removeChain(tag); return; } if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5") || tag.equals("h6")) { cprops.removeChain(tag); return; } if (tag.equals("table")) { if (pendingTR) endElement("tr"); cprops.removeChain("table"); IncTable table = (IncTable) stack.pop(); PdfPTable tb = table.buildTable(); tb.setSplitRows(true); if (stack.empty()) document.add(tb); else ((TextElementArray) stack.peek()).add(tb); boolean state[] = (boolean[]) tableState.pop(); pendingTR = state[0]; pendingTD = state[1]; skipText = false; return; } if (tag.equals("tr")) { if (pendingTD) endElement("td"); pendingTR = false; cprops.removeChain("tr"); ArrayList cells = new ArrayList(); IncTable table = null; while (true) { Object obj = stack.pop(); if (obj instanceof IncCell) { cells.add(((IncCell) obj).getCell()); } if (obj instanceof IncTable) { table = (IncTable) obj; break; } } table.addCols(cells); table.endRow(); stack.push(table); skipText = true; return; } if (tag.equals("td") || tag.equals("th")) { pendingTD = false; cprops.removeChain("td"); skipText = true; return; } } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:org.activityinfo.server.report.renderer.itext.ItextMapRenderer.java
License:Open Source License
private void addPieChartDescription(MapReportElement element, Cell descriptionCell, PiechartMapLayer layer) throws BadElementException, IOException { for (Slice slice : layer.getSlices()) { IndicatorDTO indicator = element.getContent().getIndicatorById(slice.getIndicatorId()); Color color = ColorUtil.colorFromString(slice.getColor()); ItextGraphic sliceImage = renderSlice(imageCreator, color, 10); Chunk box = new Chunk(sliceImage.toItextImage(), 0, 0); Chunk description = new Chunk(indicator.getName()); Phrase phrase = new Phrase(); phrase.add(box);//from ww w . j av a 2s . c om phrase.add(description); Paragraph paragraph = new Paragraph(phrase); descriptionCell.add(paragraph); } }
From source file:org.areasy.common.doclet.document.tags.HtmlTag.java
License:Open Source License
/** * This method must be implemented by subclasses in order * to provide a mechanism to convert an HTML tag into * a PDF document object.//from w ww .ja v a 2s. c o m * * @param text The text with HTML tags. * @return The PDF Element representint that HTML code. */ public Element toElement(String text) { if (!isPre()) text = DocletUtility.stripLineFeeds(text); Phrase result = new Phrase(); result.add(new Chunk(text, getFont())); return result; }
From source file:org.areasy.common.doclet.document.tags.TagA.java
License:Open Source License
public Element toElement(String text) { String addr = getAttribute("href"); if (addr == null || !DefaultConfiguration.isLinksCreationActive()) addr = ""; if (!isPre()) text = DocletUtility.stripLineFeeds(text); Element aChunk;/* w ww. j av a 2 s . c o m*/ if (addr.startsWith("locallink")) { boolean plainText = addr.startsWith("locallinkplain"); String dest = addr.substring(addr.indexOf(':') + 1).trim(); setCode(!plainText); return new LinkPhrase(dest, text, Math.max(9, (int) getFont().size()), plainText); } else if (addr.equalsIgnoreCase("newpage")) return super.toElement(text); else if (addr.startsWith("http://") || addr.startsWith("https://")) { try { URL url = new URL(addr); return new Chunk(text, getFont()).setAnchor(url); } catch (MalformedURLException e) { log.error("Malformed URL: " + addr); } } else { String fileName = addr.trim(); String anchorName = ""; int hashIndex = addr.indexOf('#'); if (hashIndex >= 0) { fileName = addr.substring(0, hashIndex).trim(); anchorName = addr.substring(hashIndex + 1).trim(); } boolean isLocalAnchor = (fileName.length() == 0 && anchorName.length() > 0); File file = null; try { if (fileName.length() > 0) file = new File(DocletUtility.getFilePath(fileName)); else file = State.getCurrentFile(); } catch (FileNotFoundException e) { log.debug("Could not find linked file " + fileName); } if (isLocalAnchor || Destinations.isValidDestinationFile(file)) { String fullAnchor = Destinations.createAnchorDestination(file, anchorName); PdfAction action = new PdfAction("", ""); action.remove(PdfName.F); action.put(PdfName.S, PdfName.GOTO); action.put(PdfName.D, new PdfString(fullAnchor)); aChunk = new Phrase(); Chunk chunk = createChunk(text); ((Phrase) aChunk).add(chunk.setAction(action)); return aChunk; } } if (getAttribute("name") != null) setLink(false); // no underline for anchors Font font = getFont(); font.setColor(0, 0, 0); aChunk = new Chunk(text, font); setLink(false); return aChunk; }
From source file:org.areasy.common.doclet.document.tags.TagTABLE.java
License:Open Source License
public void addNestedTagContent(Element[] elements) { PdfPCell[] row = getRow(elements);/*from w w w .jav a2 s. co m*/ // If elements is a row of Cells, add it to the table if (row != null) { if (table == null) { createTable(getNumColumns(row)); hasHeaders = isHeader(row[0]); } else if (!isHeader(row[0]) && hasHeaders) { table.setHeaderRows(table.size()); hasHeaders = false; } for (int i = 0; i < row.length; i++) { row[i].setBorderWidth(table.getDefaultCell().borderWidth()); row[i].setBorderColor(table.getDefaultCell().borderColor()); row[i].setBorder(table.getDefaultCell().border()); row[i].setPadding(table.getDefaultCell().getPaddingLeft()); table.addCell(row[i]); } /* If we haven't finished a row, fill it out. Not sure this is a good idea. */ int col = getCurrCol(table); int expectedCols = table.getAbsoluteWidths().length; if (col > 0) { for (int i = col; i < expectedCols; i++) { table.addCell(new PdfPCell(new Phrase())); } } } }
From source file:org.areasy.common.doclet.utilities.PDFUtility.java
License:Open Source License
/** * Creates a table cell without border and without * padding for a given Element./* ww w . java 2 s .c o m*/ * * @param padding The padding for the cell. * @param element The content element. * @return The PdfPCell object. */ public static PdfPCell createElementCell(int padding, Element element) { // PdfPTable and List objects must be added to the cell directly. // If they are wrapped up in a Phrase or Paragraph, they won't show up. if (element instanceof PdfPTable) return new CellNoBorderWithPadding(padding, (PdfPTable) element); if (element instanceof List) return new CellNoBorderWithPadding(padding, (List) element); // Everything else can be wrapped in a Phrase. Phrase newPhrase = new Phrase(); newPhrase.add(element); return new CellNoBorderWithPadding(padding, newPhrase); }
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// w ww . j a v a2 s.c o m **/ 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.cocktail.superplan.server.gestionimpression.TabularEdtReport.java
License:CeCILL license
public NSData genererPdf(NSArray creneaux, NSTimestamp debutSemaine, String semaine, String libelleFormation) throws DocumentException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter.getInstance(document, os); document.open();// w w w. j av a 2 s.c o m document.setMargins(0, 0, 0, 0); Font font = new Font(Font.TIMES_ROMAN, 12, Font.BOLD, Color.DARK_GRAY); PdfPTable headerTable = new PdfPTable(1); PdfPCell cell = new PdfPCell(); Phrase ph = new Phrase(); ph.add(new Chunk(libelleFormation, font)); cell.setPhrase(ph); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); font = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, Color.DARK_GRAY); cell = new PdfPCell(); ph = new Phrase(); ph.add(new Chunk(semaine, font)); cell.setPhrase(ph); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); headerTable.setWidthPercentage(100); headerTable.setSpacingAfter(5.0f); document.add(headerTable); PdfPTable pdfTable = creerCreneauxTable(creneaux, debutSemaine); pdfTable.setWidthPercentage(100); document.add(pdfTable); document.close(); return new NSData(os.toByteArray()); }