public void addElement( Element element ) { // in function add(Element element) chunks are cloned // it is not correct for chunks with dynamic content (ie page number) // use function add(int index, Element element) because in this function chunks are added without cloning super.add( size(), element ); }
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 Element createFooter() { final Paragraph footer = new Paragraph(); footer.add(new Phrase("Generated using ", FONT_FOOTER)); final Anchor a = new Anchor(config.getProperty("app.name"), FONT_FOOTER); a.setReference("http://timurstrekalov.github.com/saga/"); footer.add(a); footer.add(new Phrase(" version " + config.getProperty("app.version"), FONT_FOOTER)); footer.setAlignment(Element.ALIGN_RIGHT); return footer; }
/** * Adds a new line to the currentParagraph. * @since 5.0.6 */ public void newLine() { if (currentParagraph == null) { currentParagraph = new Paragraph(); } currentParagraph.add(createChunk("\n")); }
/** * Adds a new line to the currentParagraph. * @since 5.0.6 */ public void newLine() { if (currentParagraph == null) { currentParagraph = new Paragraph(); } currentParagraph.add(createChunk("\n")); }
/** * @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#text(java.lang.String) */ public void text(String content) { if (skipText) return; if (currentParagraph == null) { currentParagraph = createParagraph(); } if (!insidePRE) { // newlines and carriage returns are ignored if (content.trim().length() == 0 && content.indexOf(' ') < 0) { return; } content = HtmlUtilities.eliminateWhiteSpace(content); } Chunk chunk = createChunk(content); currentParagraph.add(chunk); }
/** * @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#text(java.lang.String) */ public void text(String content) { if (skipText) return; if (currentParagraph == null) { currentParagraph = createParagraph(); } if (!insidePRE) { // newlines and carriage returns are ignored if (content.trim().length() == 0 && content.indexOf(' ') < 0) { return; } content = HtmlUtilities.eliminateWhiteSpace(content); } Chunk chunk = createChunk(content); currentParagraph.add(chunk); }
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); } }
protected Paragraph formatTitle(int headerLevel, ITextContext emitterContext, BackgroundExec background) { Styles styles = emitterContext.styles(); Font font = styles.sectionTitleFontForLevel(headerLevel + 1); Paragraph p = new Paragraph(); p.add(new Chunk(background.name(), font)); p.add(new Chunk(" (", font)); p.add(new Chunk(background.keyword(), new FontCopier(font).italic().color(styles.getColor(KEYWORD_COLOR).or(BaseColor.LIGHT_GRAY)).get())); p.add(new Chunk(")", font)); return p; }
private void printHtmlParagraphs(Section section, String content, int parentLevel) throws Exception { if (content == null || content.length() == 0) return; Paragraph comb = new Paragraph(); ElementList list = XMLWorkerHelper.parseToElementList(content, null); for (Element element : list) { comb.add(element); } section.add(comb); section.add(new Paragraph("\n", normalFont)); } }
private void appendTitle(ITextContext context, Paragraph preface) { if (StringUtils.isEmpty(title)) { return; } Styles styles = context.styles(); Font font = styles.getFont(FIRST_PAGE_TITLE_FONT).or(titleFont(styles)); Paragraph paragraph = null; for (String titlePart : title.split("[\n\r]+")) { paragraph = new Paragraph(titlePart, font); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingAfter(15.0f); preface.add(paragraph); } if (paragraph != null) { paragraph.setSpacingAfter(30.0f); } }
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); }
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); }
/** * Processes an Image. * @param img * @param attrs * @throws DocumentException * @since 5.0.6 */ public void processImage(final Image img, final Map<String, String> attrs) throws DocumentException { ImageProcessor processor = (ImageProcessor)providers.get(HTMLWorker.IMG_PROCESSOR); if (processor == null || !processor.process(img, attrs, chain, document)) { String align = attrs.get(HtmlTags.ALIGN); if (align != null) { carriageReturn(); } if (currentParagraph == null) { currentParagraph = createParagraph(); } currentParagraph.add(new Chunk(img, 0, 0, true)); currentParagraph.setAlignment(HtmlUtilities.alignmentValue(align)); if (align != null) { carriageReturn(); } } }
public static Paragraph constructTitle( IParagraphFactory factory, Paragraph ancestorTitle, ArrayList numbers, int numberDepth, int numberStyle, PdfPCell cell ) { if ( ancestorTitle != null && cell != null ) { Paragraph newTitle = factory.createParagraph(); PdfPTable table = new PdfPTable( 1 ); table.setWidthPercentage( 100f ); cell.addElement( ancestorTitle ); table.addCell( cell ); newTitle.add( table ); return newTitle; } return ancestorTitle; }
@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); }
@Override public void emit(Tags tagContainer, ITextContext emitterContext) { FluentIterable<String> tags = tagContainer.tags(); if (tags.isEmpty()) return; Styles styles = emitterContext.keyValues().<Styles>getNullable(Styles.class).get(); Paragraph pTags = new Paragraph("Tags: ", styles.getFontOrDefault(Settings.META_FONT)); boolean first = true; Font tagFont = styles.getFontOrDefault(TAG_FONT); for (String text : tags) { if (first) { first = false; } else { text = ", " + text; } pTags.add(new Chunk(text, tagFont)); } emitterContext.append(pTags); } }
@Override public void process(int level, Node node, InvocationContext context) { List<Element> subs = context.collectChildren(level, node); com.itextpdf.text.List orderedList = new com.itextpdf.text.List(com.itextpdf.text.List.ORDERED); for (Element sub : subs) { if (!orderedList.add(sub)) { // wrap it ListItem listItem = new ListItem(); listItem.add(sub); orderedList.add(listItem); } } KeyValues kvs = context.iTextContext().keyValues(); Float spacingBefore = kvs.<Float>getNullable(ORDERED_LIST_SPACING_BEFORE).or(5f); Float spacingAfter = kvs.<Float>getNullable(ORDERED_LIST_SPACING_AFTER).or(5f); Paragraph p = new Paragraph(); p.add(orderedList); p.setSpacingBefore(spacingBefore); p.setSpacingAfter(spacingAfter); context.append(p); } }
@Override public void process(int level, Node node, InvocationContext context) { List<Element> subs = context.collectChildren(level, node); com.itextpdf.text.List orderedList = new com.itextpdf.text.List(com.itextpdf.text.List.UNORDERED); orderedList.setListSymbol(context.bulletSymbol()); for (Element sub : subs) { if (!orderedList.add(sub)) { // wrap it ListItem listItem = new ListItem(); listItem.add(sub); orderedList.add(listItem); } } KeyValues kvs = context.iTextContext().keyValues(); Float spacingBefore = kvs.<Float>getNullable(BULLET_LIST_SPACING_BEFORE).or(5f); Float spacingAfter = kvs.<Float>getNullable(BULLET_LIST_SPACING_AFTER).or(5f); Paragraph p = new Paragraph(); p.add(orderedList); p.setSpacingBefore(spacingBefore); p.setSpacingAfter(spacingAfter); context.append(p); } }
public List<Element> process(SourceCode sourceCode) { String lang = sourceCode.lang(); String content = sourceCode.content(); boolean linenos = sourceCode.showLineNumbers(); Tokens tokens = pygments.tokenize(lang, content); Paragraph p = new Paragraph(); for (TokenWithValue token : tokens) { Style style = styleSheet.styleOf(token.token); BaseColor color = toColor(style.fg()); int s = calculateStyle(style); Font font = styles.getFont(Styles.CODE_FONT, s, color).get(); Chunk o = new Chunk(token.value, font); RGB bg = style.bg(); if (bg != null) o.setBackground(toColor(bg)); p.add(o); } PdfPCell cell = new PdfPCell(p); cell.setPaddingBottom(5.0f); cell.setBorder(Rectangle.NO_BORDER); PdfPTable table = new PdfPTable(1); table.addCell(cell); table.setSpacingBefore(5.0f); table.setSpacingAfter(5.0f); table.setTableEvent(new TableBackground(toColor(styleSheet.backgroundColor()))); return Arrays.<Element>asList(table); }