public static Function<PageInfos, Phrase> create(final Styles styles, final Object fontKey, final String firstPageTemplate, final String otherPageTemplate, final Phrase otherPage) { return new Function<PageInfos, Phrase>() { @Override public Phrase apply(PageInfos pageInfos) { Font font = styles.getFontOrDefault(fontKey); if (pageInfos.getRawPageNumber() == 1) { if (firstPageTemplate != null) { return new Phrase(firstPageTemplate, font); } } else { if (otherPage != null) return otherPage; else if (otherPageTemplate != null) { String text = otherPageTemplate; text = text.replace("${chapterTitle}", defaultString(pageInfos.chapterTitle())); text = text.replace("${sectionTitle}", defaultString(pageInfos.sectionTitle())); return new Phrase(text, font); } } return null; } }; }
/** * Process the text so that it will render with a combination of fonts * if needed. * @param text the text * @return a <CODE>Phrase</CODE> with one or more chunks */ public Phrase process(String text) { if (fonts.size() == 0) throw new IndexOutOfBoundsException(MessageLocalization.getComposedMessage("no.font.is.defined")); char cc[] = text.toCharArray(); int len = cc.length; StringBuffer sb = new StringBuffer(); Phrase ret = new Phrase(); currentFont = null; for (int k = 0; k < len; ++k) { Chunk newChunk = processChar(cc, k, sb); if (newChunk != null) { ret.add(newChunk); } } if (sb.length() > 0) { Chunk ck = new Chunk(sb.toString(), currentFont != null ? currentFont : fonts.get(0)); ret.add(ck); } return ret; }
/** * Copy constructor for <CODE>Phrase</CODE>. * @param phrase the Phrase to copy */ public Phrase(final Phrase phrase) { super(); this.addAll(phrase); setLeading(phrase.getLeading(), phrase.getMultipliedLeading()); font = phrase.getFont(); tabSettings = phrase.getTabSettings(); setHyphenation(phrase.getHyphenation()); }
/** * Adds an <CODE>Element</CODE> to the <CODE>Paragraph</CODE>. * * @param o the element to add. * @return true is adding the object succeeded */ @Override public boolean add(Element o) { if (o instanceof List) { List list = (List) o; list.setIndentationLeft(list.getIndentationLeft() + indentationLeft); list.setIndentationRight(indentationRight); return super.add(list); } else if (o instanceof Image) { super.addSpecial(o); return true; } else if (o instanceof Paragraph) { super.addSpecial(o); return true; } return super.add(o); }
Phrase p = new Phrase(true); p.setLeading(leading); p.font = font; if (font.getFamily() != FontFamily.SYMBOL && font.getFamily() != FontFamily.ZAPFDINGBATS && font.getBaseFont() == null) { if (index > 0) { String firstPart = string.substring(0, index); p.add(new Chunk(firstPart, font)); string = string.substring(index); string = string.substring(1); p.add(new Chunk(buf.toString(), symbol)); p.add(new Chunk(string, font));
/** * Adds a collection of <CODE>Chunk</CODE>s * to this <CODE>Phrase</CODE>. * * @param collection a collection of <CODE>Chunk</CODE>s, <CODE>Anchor</CODE>s and <CODE>Phrase</CODE>s. * @return <CODE>true</CODE> if the action succeeded, <CODE>false</CODE> if not. * @throws ClassCastException when you try to add something that isn't a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE> */ @Override public boolean addAll(final Collection<? extends Element> collection) { for (Element e: collection) { this.add(e); } return true; }
Phrase content = new Phrase("Blah blah blah", Font); Float fontSize = content.getFont().getSize(); Float capHeight = content.getFont().getBaseFont().getFontDescriptor(BaseFont.CAPHEIGHT, fontSize); Float padding = 5f; PdfPCell cell = new PdfPCell(content); cell.setPadding(padding); cell.setPaddingTop(capHeight - fontSize + padding);
@SuppressWarnings("unchecked") @Override public void process(int level, Node node, InvocationContext context) { TreeNavigation nav = context.treeNavigation(); boolean isHeaderCell = nav.ancestorTreeMatches(TableCellNode.class, TableRowNode.class, TableHeaderNode.class); CellStyler cellStyler = context.peekCellStyler(); context.pushFont(cellStyler.cellFont()); List<Element> elements = context.collectChildren(level, node); context.popFont(); Phrase phrase = new Phrase(); phrase.addAll(elements); int colspan = ((TableCellNode) node).getColSpan(); PdfPCell cell = isHeaderCell ? headerCell(phrase) : new PdfPCell(phrase); cell.setColspan(colspan); cellStyler.applyStyle(cell); context.append(cell); }
Phrase p = new Phrase(true); p.setLeading(leading); p.font = font; if (font.getFamily() != FontFamily.SYMBOL && font.getFamily() != FontFamily.ZAPFDINGBATS && font.getBaseFont() == null) { if (index > 0) { String firstPart = string.substring(0, index); p.add(new Chunk(firstPart, font)); string = string.substring(index); string = string.substring(1); p.add(new Chunk(buf.toString(), symbol)); p.add(new Chunk(string, font));
/** * Adds an <CODE>Element</CODE> to the <CODE>Paragraph</CODE>. * * @param o the element to add. * @return true is adding the object succeeded */ @Override public boolean add(Element o) { if (o instanceof List) { List list = (List) o; list.setIndentationLeft(list.getIndentationLeft() + indentationLeft); list.setIndentationRight(indentationRight); return super.add(list); } else if (o instanceof Image) { super.addSpecial(o); return true; } else if (o instanceof Paragraph) { super.addSpecial(o); return true; } return super.add(o); }
/** * Adds a collection of <CODE>Chunk</CODE>s * to this <CODE>Phrase</CODE>. * * @param collection a collection of <CODE>Chunk</CODE>s, <CODE>Anchor</CODE>s and <CODE>Phrase</CODE>s. * @return <CODE>true</CODE> if the action succeeded, <CODE>false</CODE> if not. * @throws ClassCastException when you try to add something that isn't a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE> */ @Override public boolean addAll(final Collection<? extends Element> collection) { for (Element e: collection) { this.add(e); } return true; }
/** * Adds a <CODE>Chunk</CODE> to the current text array. Will not have any * effect if addElement() was called before. * * @param chunk the text */ public void addText(final Chunk chunk) { if (chunk == null || composite) { return; } addText(new Phrase(chunk)); }
/** * Process the text so that it will render with a combination of fonts * if needed. * @param text the text * @return a <CODE>Phrase</CODE> with one or more chunks */ public Phrase process(String text) { if (getSize() == 0) throw new IndexOutOfBoundsException(MessageLocalization.getComposedMessage("no.font.is.defined")); char cc[] = text.toCharArray(); int len = cc.length; StringBuffer sb = new StringBuffer(); Phrase ret = new Phrase(); currentFont = null; for (int k = 0; k < len; ++k) { Chunk newChunk = processChar(cc, k, sb); if (newChunk != null) { ret.add(newChunk); } } if (sb.length() > 0) { Chunk ck = new Chunk(sb.toString(), currentFont != null ? currentFont : getFont(0)); ret.add(ck); } return ret; }
@Override public void process(int level, Node node, InvocationContext context) { ExpLinkNode linkNode = (ExpLinkNode) node; String url = context.variableResolver().resolve(linkNode.url); Font anchorFont = new FontCopier(context.peekFont()) .style(Font.UNDERLINE) .color(Colors.DARK_RED) .get(); context.pushFont(anchorFont); List<Element> subs = context.collectChildren(level, node); context.popFont(); Phrase p = new Phrase(); p.addAll(subs); Anchor anchor = new Anchor(p); anchor.setReference(url); context.append(anchor); } }
/** * Copy constructor for <CODE>Phrase</CODE>. * @param phrase the Phrase to copy */ public Phrase(final Phrase phrase) { super(); this.addAll(phrase); setLeading(phrase.getLeading(), phrase.getMultipliedLeading()); font = phrase.getFont(); tabSettings = phrase.getTabSettings(); setHyphenation(phrase.getHyphenation()); }
/** * Adds a cell element. * * @param text the text for the cell */ public void addCell(final String text) { addCell(new Phrase(text)); }
private void printVariables(Chapter chapter, List<Variable> variables, int parentLevel) { Paragraph sTitle = new Paragraph("Process Variables", sectionFont); Section section = chapter.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1)); com.itextpdf.text.List list = new com.itextpdf.text.List(false, false, 10.0f); for (Variable var : variables) { Phrase phrase = new Phrase(); phrase.add(new Chunk(var.getName(), fixedWidthFont)); String v = var.getType(); if (var.getDescription() != null) v += " (" + var.getDescription() + ")"; phrase.add(new Chunk(": " + v + "\n", normalFont)); list.add(new ListItem(phrase)); } section.add(list); }