private PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){ PdfPCell cell=new PdfPCell(); cell.setPadding(0); cell.setBorder(Rectangle.NO_BORDER); Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline()); String fontColor=phf.getForecolor(); if(StringUtils.isNotEmpty(fontColor)){ String[] color=fontColor.split(","); font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2])); } Paragraph graph=new Paragraph(text,font); cell.setPhrase(graph); switch(type){ case 1: cell.setHorizontalAlignment(Element.ALIGN_LEFT); break; case 2: cell.setHorizontalAlignment(Element.ALIGN_CENTER); break; case 3: cell.setHorizontalAlignment(Element.ALIGN_RIGHT); break; } cell.setVerticalAlignment(Element.ALIGN_MIDDLE); return cell; } }
private void addTitlePage(Document document) throws DocumentException { addEmptyLine(document, 5); Paragraph title = new Paragraph("Data Dictionary by Arrah technology"); title.setAlignment(Element.ALIGN_CENTER); document.add(title); addEmptyLine(document, 1); Paragraph url = new Paragraph("http://sourceforge.net/projects/dataquality/"); url.setAlignment(Element.ALIGN_CENTER); document.add(url); addEmptyLine(document, 3); Paragraph rtime = new Paragraph("Report generated on: " + new Date()); rtime.setAlignment(Element.ALIGN_CENTER); document.add(rtime); document.newPage(); }
/** * Creates a shallow clone of the Paragraph. * @return */ public Paragraph cloneShallow(boolean spacingBefore) { Paragraph copy = new Paragraph(); populateProperties(copy, spacingBefore); return copy; }
protected void populateProperties(Paragraph copy, boolean spacingBefore) { copy.setFont(getFont()); copy.setAlignment(getAlignment()); copy.setLeading(getLeading(), multipliedLeading); copy.setIndentationLeft(getIndentationLeft()); copy.setIndentationRight(getIndentationRight()); copy.setFirstLineIndent(getFirstLineIndent()); copy.setSpacingAfter(getSpacingAfter()); if (spacingBefore) copy.setSpacingBefore(getSpacingBefore()); copy.setExtraParagraphSpace(getExtraParagraphSpace()); copy.setRole(role); copy.id = getId(); if (accessibleAttributes != null) copy.accessibleAttributes = new HashMap<PdfName, PdfObject>(accessibleAttributes); copy.setTabSettings(getTabSettings()); copy.setKeepTogether(getKeepTogether()); }
/** * Constructs a <CODE>Paragraph</CODE> with a certain <CODE>Phrase</CODE>. * * @param phrase a <CODE>Phrase</CODE> */ public Paragraph(Phrase phrase) { super(phrase); if (phrase instanceof Paragraph) { Paragraph p = (Paragraph)phrase; setAlignment(p.alignment); setIndentationLeft(p.getIndentationLeft()); setIndentationRight(p.getIndentationRight()); setFirstLineIndent(p.getFirstLineIndent()); setSpacingAfter(p.getSpacingAfter()); setSpacingBefore(p.getSpacingBefore()); setExtraParagraphSpace(p.getExtraParagraphSpace()); setRole(p.role); id = p.getId(); if (p.accessibleAttributes != null) accessibleAttributes = new HashMap<PdfName, PdfObject>(p.accessibleAttributes); } }
private void addTitle(Document document) throws DocumentException { Paragraph title = new Paragraph(exportConf.getFileName()); title.add(new Paragraph(" ")); // empty line title.setAlignment(Element.ALIGN_CENTER); document.add(title); }
@Override public void process(int level, Node node, InvocationContext context) { List<Element> subs = context.collectChildren(level, node); Paragraph p = new Paragraph(); for (Element sub : subs) { p.add(discardNewline(sub)); } KeyValues kvs = context.iTextContext().keyValues(); Float spacingBefore = kvs.<Float>getNullable(PARAGRAPH_SPACING_BEFORE).or(5f); Float spacingAfter = kvs.<Float>getNullable(PARAGRAPH_SPACING_AFTER).or(5f); p.setSpacingBefore(spacingBefore); p.setSpacingAfter(spacingAfter); applyAttributes(context, p); context.append(p); }
private void appendSubject(ITextContext context, Paragraph preface) { if (StringUtils.isEmpty(subject)) { return; } Styles styles = context.styles(); Font font = styles.getFont(FIRST_PAGE_SUBJECT_FONT).or(subjectFont(styles)); for (String titlePart : subject.split("[\n\r]+")) { Paragraph paragraph = new Paragraph(titlePart, font); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingAfter(15.0f); preface.add(paragraph); } }
public ColumnText generateTableOfContent(ITextContext context) { ColumnText ct = new ColumnText(null); Styles styles = context.styles(); Chunk CONNECT = connectChunk(styles); Paragraph paragraph = new Paragraph(); paragraph.setSpacingBefore(20.0f); // first paragraph only ct.addElement(new Paragraph("Table of content", styles.sectionTitleFontForLevel(1))); ct.addElement(new Paragraph("")); Font entryFont = styles.getFontOrDefault(TOC_ENTRY_FONT); TableOfContents tableOfContents = context.tableOfContents(); for (TableOfContents.Entry entry : tableOfContents.getEntries()) { //if (entry.isExtra()) // continue; Chunk chunk = new Chunk(entry.getText(), entryFont); paragraph.add(chunk); paragraph.add(CONNECT); paragraph.add(new Chunk("" + entry.getFormattedPageNumber(), entryFont)); float indent = 10.0f * entry.getLevel(); paragraph.setIndentationLeft(indent); ct.addElement(paragraph); paragraph = new Paragraph(); } return ct; }
BaseColor regexBg = styles.getColor(Styles.INLINE_CODE_BACKGROUND).or(BaseColor.LIGHT_GRAY); Paragraph p = new Paragraph(); p.setSpacingBefore(5f); if (!Strings.isNullOrEmpty(methodEntry.comment())) { List<Element> subs = context.emitButCollectElements(Markdown.from(methodEntry.comment())); p.addAll(subs); p.add(Chunk.NEWLINE); for (KeywordBasedPattern kwPattern : methodEntry.keywordBasedPatterns()) { if(nb++ > 0) p.add(Chunk.NEWLINE); regexChunk.setBackground(regexBg); p.add(keywordChunk); p.add(new Chunk(" ")); p.add(regexChunk); p.add(Chunk.NEWLINE); p.add(lineSeparator); p.add(Chunk.NEWLINE);
/** * Constructs a Paragraph that will be used as title for a Section or Chapter. * @param title the title of the section * @param numbers a list of sectionnumbers * @param numberDepth how many numbers have to be shown * @param numberStyle the numbering style * @return a Paragraph object * @since iText 2.0.8 */ public static Paragraph constructTitle(final Paragraph title, final ArrayList<Integer> numbers, final int numberDepth, final int numberStyle) { if (title == null) { return null; } int depth = Math.min(numbers.size(), numberDepth); if (depth < 1) { return title; } StringBuffer buf = new StringBuffer(" "); for (int i = 0; i < depth; i++) { buf.insert(0, "."); buf.insert(0, numbers.get(i).intValue()); } if (numberStyle == NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT) { buf.deleteCharAt(buf.length() - 2); } Paragraph result = new Paragraph(title); result.add(0, new Chunk(buf.toString(), title.getFont())); return result; }
/** * Adds a link to the current paragraph. * @since 5.0.6 */ public void processLink() { if (currentParagraph == null) { currentParagraph = new Paragraph(); } // The link provider allows you to do additional processing LinkProcessor i = (LinkProcessor) providers.get(HTMLWorker.LINK_PROVIDER); if (i == null || !i.process(currentParagraph, chain)) { // sets an Anchor for all the Chunks in the current paragraph String href = chain.getProperty(HtmlTags.HREF); if (href != null) { for (Chunk ck : currentParagraph.getChunks()) { ck.setAnchor(href); } } } // a link should be added to the current paragraph as a phrase if (stack.isEmpty()) { // no paragraph to add too, 'a' tag is first element Paragraph tmp = new Paragraph(new Phrase(currentParagraph)); currentParagraph = tmp; } else { Paragraph tmp = (Paragraph) stack.pop(); tmp.add(new Phrase(currentParagraph)); currentParagraph = tmp; } }
paragraph.setAlignment(HtmlUtilities.alignmentValue(value)); paragraph.setHyphenation(getHyphenation(chain)); if (value != null) { try { paragraph.setSpacingBefore(Float.parseFloat(value)); } catch (Exception e) { if (value != null) { try { paragraph.setSpacingAfter(Float.parseFloat(value)); } catch (Exception e) { if (value != null) { try { paragraph.setExtraParagraphSpace(Float.parseFloat(value)); } catch (Exception e) { if (value != null) { try { paragraph.setIndentationLeft(Float.parseFloat(value)); } catch (Exception e) {
for (Element e : this) { if (e.type() == Element.LIST || e.type() == Element.PTABLE || e.type() == Element.PARAGRAPH) { if (tmp != null && tmp.size() > 0) { tmp.setSpacingAfter(0); list.add(tmp); tmp = cloneShallow(false); ((PdfPTable) e).setSpacingBefore(getSpacingBefore()); break; case Element.PARAGRAPH: ((Paragraph) e).setSpacingBefore(getSpacingBefore()); break; case Element.LIST: ListItem firstItem = ((List)e).getFirstItem(); if (firstItem != null) { firstItem.setSpacingBefore(getSpacingBefore()); tmp = cloneShallow(list.size() == 0); tmp.add(e); if (tmp != null && tmp.size() > 0) { list.add(tmp); switch (lastElement.type()) { case Element.PTABLE : ((PdfPTable)lastElement).setSpacingAfter(getSpacingAfter()); break; case Element.PARAGRAPH :
public static Paragraph formatStep(StepExec step, boolean includeKeyword, Styles styles, ITextContext emitterContext) { Font stepKeywordFont = styles.getFontOrDefault(STEP_KEYWORD_FONT); Font stepPhraseFont = styles.getFontOrDefault(STEP_PHRASE_FONT); Font stepParamFont = styles.getFontOrDefault(STEP_PARAMETER_FONT); Paragraph pPhrase = new Paragraph(); if (includeKeyword) { pPhrase.add(new Chunk(step.keyword(), stepKeywordFont)); pPhrase.add(new Chunk(" ")); } if (!step.isMatching()) { pPhrase.add(new Chunk(step.name(), stepPhraseFont)); } else { for (StepExec.Tok tok : step.tokenizeBody()) { Font tokFont = stepPhraseFont; if (tok.param) tokFont = stepParamFont; List<Element> richText = emitterContext.emitButCollectElements(new RichText(tok.value, tokFont)); pPhrase.addAll(richText); } } return pPhrase; }
private void addContent(final TestRunCoverageStatistics runStats) throws DocumentException { final Paragraph title = new Paragraph(runStats.title, FONT_H1); title.setIndentationLeft(PADDING_LEFT); document.add(title); document.add(createTable(runStats)); document.add(createFooter()); }
@Override public void process(int level, Node node, InvocationContext context) { HeaderNode hNode = (HeaderNode) node; int hLevel = hNode.getLevel(); Sections sections = context.iTextContext().sections(); Font font = sections.sectionTitlePrimaryFont(hLevel); context.pushFont(font); List<Element> subs = context.collectChildren(level, node); context.popFont(); Paragraph p = new Paragraph(); p.setFont(font); p.addAll(subs); Element element = sections.newSection(p, hLevel); context.append(element); } }
private void printGraphDocumentation(Process process, Chapter chapter) throws Exception { Section section; String tmp; if (process.isEmbeddedProcess()) { String id = process.getAttribute(WorkAttributeConstant.LOGICAL_ID); if (id == null || id.length() == 0) id = process.getId().toString(); tmp = "Subprocess " + id + ": \"" + process.getName().replace('\n', ' ') + "\""; } else { tmp = "Process Description"; } Paragraph sTitle = new Paragraph(tmp, sectionFont); sTitle.setSpacingBefore(10); section = chapter.addSection(sTitle, 2); String summary = process.getDescription(); if (summary != null && summary.length() > 0) printBoldParagraphs(section, summary); String detail = process.getAttribute(WorkAttributeConstant.DOCUMENTATION); if (detail != null && detail.length() > 0) { printHtmlParagraphs(section, getHtmlContent(detail), 0); } if (!process.getAttributes().isEmpty() && process.isEmbeddedProcess()) { printAttributes(section, process.getAttributes(), 2); } }