List of usage examples for com.lowagie.text.pdf PdfPCell setPaddingBottom
public void setPaddingBottom(float paddingBottom)
From source file:org.areasy.common.doclet.utilities.PDFUtility.java
License:Open Source License
/** * Create a cell element./*from w w w. j a va2 s . c om*/ */ public static PdfPCell createElementCell(int padding, int alignment, Element[] elements) { Element mainElement; // If there are no nested tables in content if (!hasTablesOrLists(elements)) { Paragraph para = new Paragraph(); para.setAlignment(alignment); for (int i = 0; i < elements.length; i++) { try { para.add(elements[i]); } catch (Exception e) { String msg = "Failed to add element to paragraph: " + e.toString(); DocletUtility.error(msg); } } mainElement = para; } else { PdfPTable cellTable = new PdfPTable(1); Paragraph currInnerPara = null; for (int i = 0; i < elements.length; i++) { Element element = elements[i]; /* Check for special element created by TagTABLE */ if (element instanceof TableParagraph) element = ((TableParagraph) elements[i]).getTable(); if (element instanceof PdfPTable || element instanceof List) { if (currInnerPara != null) { PdfPCell innerCell = createElementCell(0, alignment, currInnerPara); innerCell.setUseDescender(true); // needs newer iText innerCell.setUseAscender(true); // needs newer iText innerCell.setPaddingBottom(2.0f); cellTable.addCell(innerCell); } currInnerPara = null; cellTable.addCell(createElementCell(0, alignment, element)); } else { if (currInnerPara == null) { currInnerPara = new Paragraph(); currInnerPara.setAlignment(alignment); } try { currInnerPara.add(element); } catch (Exception e) { String msg = "Failed to add element to inner paragraph: " + e.toString(); DocletUtility.error(msg); } } } if (currInnerPara != null) cellTable.addCell(createElementCell(0, alignment, currInnerPara)); mainElement = cellTable; } return createElementCell(padding, alignment, mainElement); }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private PdfPCell newCell(Paragraph p) throws BadElementException { PdfPCell c = new PdfPCell(p); c.setBorder(PdfPCell.BOX);/*www.j a v a2s. c om*/ c.setBorderWidth(0.1f); c.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c.setPaddingBottom(3f); c.setPaddingLeft(3f); c.setPaddingRight(3f); c.setPaddingTop(0f); c.setUseBorderPadding(true); return c; }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private PdfPCell newDescriptionCell(String s) throws DocumentException, IOException { PdfPCell c = newCell(s); c.setPaddingBottom(5f); c.setPaddingLeft(5f);/*from ww w . j a v a2 s. c om*/ c.setPaddingRight(5f); c.setPaddingTop(2f); return c; }
From source file:org.mapfish.print.config.layout.CellConfig.java
License:Open Source License
protected void apply(PdfPCell cell, RenderingContext context, PJsonObject params) { if (paddingLeft != null) cell.setPaddingLeft(paddingLeft.floatValue()); if (paddingRight != null) cell.setPaddingRight(paddingRight.floatValue()); if (paddingTop != null) cell.setPaddingTop(paddingTop.floatValue()); if (paddingBottom != null) cell.setPaddingBottom(paddingBottom.floatValue()); if (borderWidthLeft != null) cell.setBorderWidthLeft(borderWidthLeft.floatValue()); if (borderWidthRight != null) cell.setBorderWidthRight(borderWidthRight.floatValue()); if (borderWidthTop != null) cell.setBorderWidthTop(borderWidthTop.floatValue()); if (borderWidthBottom != null) cell.setBorderWidthBottom(borderWidthBottom.floatValue()); if (getBorderColorLeftVal(context, params) != null) cell.setBorderColorLeft(getBorderColorLeftVal(context, params)); if (getBorderColorRightVal(context, params) != null) cell.setBorderColorRight(getBorderColorRightVal(context, params)); if (getBorderColorTopVal(context, params) != null) cell.setBorderColorTop(getBorderColorTopVal(context, params)); if (getBorderColorBottomVal(context, params) != null) cell.setBorderColorBottom(getBorderColorBottomVal(context, params)); if (getBackgroundColorVal(context, params) != null) cell.setBackgroundColor(getBackgroundColorVal(context, params)); if (align != null) cell.setHorizontalAlignment(align.getCode()); if (vertAlign != null) cell.setVerticalAlignment(vertAlign.getCode()); }
From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") public Element getElement() { if (!elementPostProcessed) { elementPostProcessed = true;//from w ww.j a v a2s .c o m // add space if this paragraph is empty // otherwise it's height will be zero boolean empty = true; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) { empty = false; break; } } if (empty) { super.add(new Chunk("\u00A0")); // non breaking space } // adjust line height and baseline if (font != null && font.getBaseFont() != null) { // iText and open office computes proportional line height differently // [iText] line height = coefficient * font size // [open office] line height = coefficient * (font ascender + font descender + font extra margin) // we have to increase paragraph line height to generate pdf similar to open office document // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph float size = font.getSize(); float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size); float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size); float multiplier = (ascender + descender + margin) / size; if (multipliedLeading > 0.0f) { setMultipliedLeading(getMultipliedLeading() * multiplier); } // iText seems to output text with baseline lower than open office // we raise all paragraph text by some amount // again this may be inaccurate if fonts with different size are used in this paragraph float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier; chunks = getChunks(); for (Chunk chunk : chunks) { Font f = chunk.getFont(); if (f != null) { // have to raise underline and strikethru as well float s = f.getSize(); if (f.isUnderlined()) { f.setStyle(f.getStyle() & ~Font.UNDERLINE); chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise); } if (f.isStrikethru()) { f.setStyle(f.getStyle() & ~Font.STRIKETHRU); chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise); } } chunk.setTextRise(chunk.getTextRise() + textRise); } } // wrap this paragraph into a table if necessary if (wrapperCell != null) { // background color or borders were set wrapperCell.addElement(this); wrapperTable = createTable(wrapperCell); if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f || getSpacingAfter() > 0.0f) { // margins were set, have to wrap the cell again PdfPCell outerCell = createCell(); outerCell.setPaddingLeft(getIndentationLeft()); setIndentationLeft(0.0f); outerCell.setPaddingRight(getIndentationRight()); setIndentationRight(0.0f); outerCell.setPaddingTop(getSpacingBefore()); setSpacingBefore(0.0f); outerCell.setPaddingBottom(getSpacingAfter()); setSpacingAfter(0.0f); outerCell.addElement(wrapperTable); wrapperTable = createTable(outerCell); } } } return wrapperTable != null ? wrapperTable : this; }
From source file:org.posterita.core.CrossTabReportGenerator.java
License:Open Source License
protected void writeDocument(Document document) throws OperationException { try {/* ww w .ja va2 s .c o m*/ int noOfRows = dataSource.size(); String longestText = ""; int columnCount = 0; Object[] obj = null; Object[] header = (Object[]) dataSource.get(0); columnCount = header.length; PdfPTable table = new PdfPTable(columnCount); table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setPaddingBottom(5); table.getDefaultCell().setPaddingTop(5); //adding the headers for (int i = 0; i < columnCount; i++) { if (i == 0) { longestText = header[i].toString(); table.addCell(new Paragraph(header[i].toString())); } else { Image img = getTextAsImage(header[i].toString()); img.setRotationDegrees(90); img.setAlignment(Image.ALIGN_BOTTOM); PdfPCell cell = new PdfPCell(img); cell.setPadding(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); //cell.setBackgroundColor(new Color(0, 0, 255)); table.addCell(cell); } } //adding the data for (int j = 1; j < noOfRows; j++) { obj = (Object[]) dataSource.get(j); for (int k = 0; k < columnCount; k++) { if (k == 0) { String text = obj[0].toString(); if (new Chunk(text, HEADER_FONT).getWidthPoint() > new Chunk(longestText, HEADER_FONT) .getWidthPoint()) { longestText = text; } Chunk txtck = new Chunk(obj[0].toString(), HEADER_FONT); PdfPCell cell = new PdfPCell(new Paragraph(txtck)); if (j == noOfRows - 1) { cell.setBackgroundColor(new Color(170, 170, 170)); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); cell.setPaddingLeft(5); table.addCell(cell); } else { Chunk txtck = new Chunk(obj[k].toString(), DATA_FONT); if (k == columnCount - 1) { PdfPCell cell = new PdfPCell(new Paragraph(txtck)); cell.setBackgroundColor(new Color(170, 170, 170)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); table.addCell(cell); } else { PdfPCell cell = new PdfPCell(new Paragraph(txtck)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); if (j == noOfRows - 1) { cell.setBackgroundColor(new Color(170, 170, 170)); } table.addCell(cell); } } } } //setting table width Chunk dataChk = new Chunk("9999", DATA_FONT); Chunk headerChk = new Chunk(longestText, HEADER_FONT); float dataChkLength = dataChk.getWidthPoint() + 2 * CELLPADDING; float headerChkLength = headerChk.getWidthPoint() + 2 * CELLPADDING; float tableWidth = headerChkLength + dataChkLength * columnCount; float actualTableWidth = document.getPageSize().getWidth() - 2 * MARGIN; float columnWidth = dataChkLength; if (tableWidth < actualTableWidth) { columnWidth = (actualTableWidth - headerChkLength) / (columnCount - 1); } float[] widths = new float[columnCount]; widths[0] = headerChkLength + 2 * CELLPADDING; for (int i = 1; i < columnCount; i++) { widths[i] = columnWidth; } table.setWidths(widths); //writing the table document.add(table); } catch (DocumentException e) { throw new OperationException(e); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the title page of the PDF document. * //from w w w.j a va 2 s . co m * @throws ExportException * If an error occurs while creating the title page */ private void writeTitlePage() throws ExportException { try { Font plainFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font boldFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font boldItalicFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading); /* * date and time of the meeting */ String meetingDate = sdfDate.format(meeting.getPlannedDate().getTime()); String meetingTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - " + sdfTime.format(meeting.getPlannedEnd().getTime()) + " [" + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]"; ; /* * Base table */ PdfPTable table = new PdfPTable(new float[] { 0.04f, 0.96f }); table.setWidthPercentage(100); table.setSplitRows(false); table.getDefaultCell().setBorderWidth(0); table.getDefaultCell().setPadding(0); /* * recipient of the invitation */ PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.addElement(phraseStrut); PdfPTable tableRecipient = new PdfPTable(2); tableRecipient.setWidthPercentage(100); tableRecipient.setSplitRows(false); tableRecipient.getDefaultCell().setBorderWidth(0); tableRecipient.getDefaultCell().setPadding(0); PdfPCell cellRecipient = new PdfPCell(); cellRecipient.setBorder(0); cellRecipient.setPadding(0); cellRecipient.addElement(new Phrase(translate("To:"), plainFontTitle)); cellRecipient.addElement(new Phrase(attendee.getName(), boldFontTitle)); tableRecipient.addCell(cellRecipient); PdfPCell cellDate = new PdfPCell(new Phrase(sdfDate.format(new Date().getTime()), plainFont)); cellDate.setHorizontalAlignment(Element.ALIGN_RIGHT); cellDate.setBorder(0); cellDate.setPadding(0); cellDate.setPaddingTop(7); tableRecipient.addCell(cellDate); cell.addElement(tableRecipient); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); /* * subject */ cell.addElement(new Phrase(translate("Invitation for the Meeting on") + " " + meetingDate, boldItalicFontTitle)); cell.addElement(phraseStrut); /* * invitation text */ Phrase phrase = new Phrase( Data.getInstance().getAppData().getSetting(AppSettingKey.PDF_INVITATION_TEXT), plainFont); phrase.setLeading(leading); cell.addElement(phrase); cell.addElement(phraseStrut); table.addCell(cell); /* * meeting date, time and location */ cell = new PdfPCell(new Phrase(meetingDate, boldItalicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(meetingTime, italicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); if (!meeting.getPlannedLocation().equals("")) { cell = new PdfPCell( new Phrase(translate("Location") + ": " + meeting.getPlannedLocation(), italicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } /* * role; review title and description */ cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.addElement(phraseStrut); cell.addElement(phraseStrut); phrase = new Phrase(); phrase.setLeading(leading); phrase.add(new Chunk(MessageFormat.format(translate("You are invited as {0} to this review ({1})."), translate(attendee.getRole().toString()), getReviewTitle()), boldFont)); cell.addElement(phrase); cell.addElement(phraseStrut); cell.addElement(new Phrase(resiData.getReview().getDescription(), italicFont)); cell.addElement(phraseStrut); /* * Predecessor meeting */ if (meetMgmt.getPredecessorMeeting(meeting) != null) { String preMeetingDate = sdfDate .format(meetMgmt.getPredecessorMeeting(meeting).getProtocol().getDate().getTime()); cell.addElement(new Phrase(MessageFormat .format(translate("This meeting ties up to the review meeting of {0}."), preMeetingDate), plainFont)); cell.addElement(phraseStrut); } /* * If there is a product name defined */ if (!Data.getInstance().getResiData().getReview().getProduct().getName().trim().equals("")) { /* * the product of this review */ cell.addElement(new Phrase(translate("The following product will be reviewed:"), plainFont)); cell.addElement(phraseStrut); table.addCell(cell); /* * Write name and version of the reviewed product */ Phrase phrName = new Phrase(Data.getInstance().getResiData().getReview().getProduct().getName(), boldItalicFont); phrName.setLeading(leading); PdfPCell cellName = new PdfPCell(phrName); cellName.setColspan(2); cellName.setBorderWidth(0); cellName.setPadding(padding); cellName.setPaddingBottom(0); cellName.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellName); /* * If there is a product version defined */ if (!Data.getInstance().getResiData().getReview().getProduct().getVersion().trim().equals("")) { Phrase phrVersion = new Phrase( translate("Product Version") + ": " + Data.getInstance().getResiData().getReview().getProduct().getVersion(), italicFont); phrVersion.setLeading(leading); PdfPCell cellVersion = new PdfPCell(phrVersion); cellVersion.setColspan(2); cellVersion.setBorderWidth(0); cellVersion.setPadding(padding); cellVersion.setPaddingBottom(0); cellVersion.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellVersion); } table.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 2)); } else { table.addCell(cell); } boolean showBottomStrut = false; /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); cellListPoint.setPaddingBottom(0); /* * Textual references */ for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) { Phrase phraseRef = new Phrase(ref, italicFontSmall); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); table.addCell(cellListPoint); table.addCell(cellRef); showBottomStrut = true; } /* * External file references */ for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), italicFontSmall)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFontSmall)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); table.addCell(cellListPoint); if (attachProdExtRefs) { cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); } table.addCell(cellRef); showBottomStrut = true; } if (showBottomStrut) { table.addCell(createVerticalStrut(PDFTools.cmToPt(0.4f), 2)); } /* * "please prepare" for the reviwers; on questions ask moderators */ cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); phrase = new Phrase(); phrase.setLeading(leading); if (attendee.getAspects() != null) { phrase.add(new Chunk(translate( "Please prepare for the review meeting by checking the product for the aspects which are associated to you.") + " ", plainFont)); } List<Attendee> moderators = new ArrayList<Attendee>(); for (Attendee a : Application.getInstance().getAttendeeMgmt().getAttendees()) { if (a.getRole() == Role.MODERATOR) { moderators.add(a); } } if (moderators.size() == 1 && attendee.getRole() != Role.MODERATOR) { phrase.add(new Chunk(translate( "Please do not hesitate to contact the review moderator if you have any questions:") + " ", plainFont)); } else if (moderators.size() > 1 && attendee.getRole() != Role.MODERATOR) { phrase.add(new Chunk(translate( "Please do not hesitate to contact one of the review moderators if you have any questions:") + " ", plainFont)); } cell.addElement(phrase); Phrase phraseStrutSmall = new Phrase(" "); phraseStrutSmall.setLeading(leading / 2); if (moderators.size() > 0 && attendee.getRole() != Role.MODERATOR) { for (Attendee mod : moderators) { cell.addElement(phraseStrutSmall); cell.addElement(new Phrase(mod.getName(), boldFont)); cell.addElement(new Phrase(mod.getContact(), italicFont)); } } table.addCell(cell); pdfDoc.add(table); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot generate front page of the PDF document.")); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the aspects.//w w w .j av a 2 s . co m * * @throws ExportException * If an error occurs while writing the aspects */ private void writeAspects() throws ExportException { /* * If the role of the attendee is not reviewer show all aspects */ List<Aspect> aspects = null; if (attendee.getRole() == Role.REVIEWER) { aspects = attMgmt.getAspects(attendee); } else { aspects = aspMgmt.getAspects(); } if (aspects.size() == 0) { return; } try { Font descriptionFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font directiveFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font categoryFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font reviewerFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); /* * Build base table for all attendees */ PdfPTable tableAspects = new PdfPTable(1); tableAspects.setWidthPercentage(100); tableAspects.setSplitRows(false); tableAspects.getDefaultCell().setBorderWidth(0); tableAspects.getDefaultCell().setPadding(0); boolean grayBackground = true; for (Aspect asp : aspects) { /* * Build table for one aspect */ PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f }); tableAspect.setWidthPercentage(100); tableAspect.getDefaultCell().setBorderWidth(0); tableAspect.getDefaultCell().setPadding(0); PdfPCell cellAspect = new PdfPCell(); cellAspect.setPadding(0); cellAspect.setBorder(0); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading * 0.4f); /* * directive and description of the aspect */ PdfPCell cell = new PdfPCell(); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingBottom(padding * 1.5f); cell.addElement(new Phrase(asp.getDirective(), directiveFont)); cell.addElement(phraseStrut); cell.addElement(new Phrase(asp.getDescription(), descriptionFont)); /* * the reviewers of this aspect (moderator only) */ if (attendee.getRole() == Role.MODERATOR) { cell.addElement(phraseStrut); cell.addElement(phraseStrut); String separator = ""; Phrase phraseReviewers = new Phrase(); phraseReviewers.setLeading(leading); phraseReviewers.setFont(reviewerFont); for (Attendee att : attMgmt.getAttendees()) { if (attMgmt.hasAspect(asp, att)) { phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont)); separator = " "; } } cell.addElement(phraseReviewers); } tableAspect.addCell(cell); /* * category of the aspect */ cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont)); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingTop(padding * 1.1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableAspect.addCell(cell); cellAspect.addElement(tableAspect); cellAspect.setPadding(0); cellAspect.setPaddingLeft(padding); cellAspect.setPaddingRight(padding); if (grayBackground == true) { grayBackground = false; cellAspect.setBackgroundColor(cellBackground); } else { grayBackground = true; } /* * Add aspect to the list */ tableAspects.addCell(cellAspect); } PdfPCell cellBottomLine = new PdfPCell(); cellBottomLine.setPadding(0); cellBottomLine.setBorderWidth(0); cellBottomLine.setBorderWidthBottom(1); cellBottomLine.setBorderColor(cellBackground); tableAspects.addCell(cellBottomLine); /* * Add the attendee base table to the document */ pdfDoc.add(tableAspects); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put aspects into the PDF document.")); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
@Override protected void writeContent() throws ExportException { try {/*w w w.j av a 2 s .c o m*/ writeTitlePage(); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); PdfPTable tableAspIntro = new PdfPTable(1); tableAspIntro.setWidthPercentage(100); Phrase phraseAspIntro; PdfPCell cellAspIntro = new PdfPCell(); cellAspIntro.setBorderWidth(0); cellAspIntro.setPadding(0); cellAspIntro.setPaddingBottom(PDFTools.cmToPt(0.8f)); if (attendee.getAspects() != null) { pdfDoc.newPage(); phraseAspIntro = new Phrase(translate( "Please prepare for the review meeting by checking the product for the following aspects step by step:"), italicFont); cellAspIntro.addElement(phraseAspIntro); tableAspIntro.addCell(cellAspIntro); pdfDoc.add(tableAspIntro); } else if (attendee.getRole() != Role.REVIEWER) { pdfDoc.newPage(); phraseAspIntro = new Phrase(translate("The product will be checked for the following aspects:"), italicFont); cellAspIntro.addElement(phraseAspIntro); tableAspIntro.addCell(cellAspIntro); pdfDoc.add(tableAspIntro); } writeAspects(); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException( translate("Cannot create invitation for the review meeting.") + "\n\n" + e.getMessage()); } }
From source file:org.revager.export.PDFPageEventHelper.java
License:Open Source License
@Override public void onEndPage(PdfWriter writer, Document document) { int columnNumber; try {//from w w w.j av a 2 s.c o m Rectangle page = document.getPageSize(); float pageWidth = page.getWidth() - document.leftMargin() - document.rightMargin(); /* * Write marks */ setMarks(writer, document); /* * Define fonts */ headBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); Font headFont = new Font(headBaseFont, headFontSize); footBaseFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED); Font footFont = new Font(footBaseFont, footFontSize); /* * Cell fill for space between head/foot and content */ PdfPCell cellFill = new PdfPCell(); cellFill.setMinimumHeight(PDFTools.cmToPt(0.8f)); cellFill.setBorderWidth(0); /* * Write head */ if (headLogoPath != null) { columnNumber = 2; } else { columnNumber = 1; } PdfPTable head = new PdfPTable(columnNumber); Phrase phraseTitle = new Phrase(headTitle, headFont); PdfPCell cellTitle = new PdfPCell(phraseTitle); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_BOTTOM); cellTitle.setPaddingTop(0); cellTitle.setPaddingBottom(PDFTools.cmToPt(0.2f)); cellTitle.setPaddingLeft(0); cellTitle.setPaddingRight(0); cellTitle.setBorderWidthTop(0); cellTitle.setBorderWidthBottom(0.5f); cellTitle.setBorderWidthLeft(0); cellTitle.setBorderWidthRight(0); head.addCell(cellTitle); if (headLogoPath != null) { Image headLogo = Image.getInstance(headLogoPath); headLogo.scaleToFit(PDFTools.cmToPt(5.0f), PDFTools.cmToPt(1.1f)); PdfPCell cellLogo = new PdfPCell(headLogo); cellLogo.setHorizontalAlignment(Element.ALIGN_RIGHT); cellLogo.setVerticalAlignment(Element.ALIGN_BOTTOM); cellLogo.setPaddingTop(0); cellLogo.setPaddingBottom(PDFTools.cmToPt(0.15f)); cellLogo.setPaddingLeft(0); cellLogo.setPaddingRight(0); cellLogo.setBorderWidthTop(0); cellLogo.setBorderWidthBottom(0.5f); cellLogo.setBorderWidthLeft(0); cellLogo.setBorderWidthRight(0); head.addCell(cellLogo); head.addCell(cellFill); } head.addCell(cellFill); head.setTotalWidth(pageWidth); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); /* * Write foot */ if (footText == null) { footText = " "; } PdfPTable foot = new PdfPTable(1); foot.addCell(cellFill); PdfPCell cellFootText = new PdfPCell(new Phrase(footText, footFont)); cellFootText.setHorizontalAlignment(Element.ALIGN_RIGHT); cellFootText.setVerticalAlignment(Element.ALIGN_TOP); cellFootText.setPaddingTop(PDFTools.cmToPt(0.15f)); cellFootText.setPaddingBottom(0); cellFootText.setPaddingLeft(0); cellFootText.setPaddingRight(0); cellFootText.setBorderWidthTop(0.5f); cellFootText.setBorderWidthBottom(0); cellFootText.setBorderWidthLeft(0); cellFootText.setBorderWidthRight(0); foot.addCell(cellFootText); /* * Print page numbers */ PdfContentByte contentByte = writer.getDirectContent(); contentByte.saveState(); String text = MessageFormat.format(translate("Page {0} of") + " ", writer.getPageNumber()); float textSize = footBaseFont.getWidthPoint(text, footFontSize); float textBase = document.bottom() - PDFTools.cmToPt(1.26f); contentByte.beginText(); contentByte.setFontAndSize(footBaseFont, footFontSize); float adjust; if (footText.trim().equals("")) { adjust = (pageWidth / 2) - (textSize / 2) - footBaseFont.getWidthPoint("0", footFontSize); } else { adjust = 0; } contentByte.setTextMatrix(document.left() + adjust, textBase); contentByte.showText(text); contentByte.endText(); contentByte.addTemplate(template, document.left() + adjust + textSize, textBase); contentByte.stroke(); contentByte.restoreState(); foot.setTotalWidth(pageWidth); foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExceptionConverter(e); } }