com.itextpdf.text.Paragraph类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(377)

本文整理了Java中com.itextpdf.text.Paragraph类的一些代码示例,展示了Paragraph类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Paragraph类的具体详情如下:
包路径:com.itextpdf.text.Paragraph
类名称:Paragraph

Paragraph介绍

[英]A Paragraph is a series of Chunks and/or Phrases.

A Paragraph has the same qualities of a Phrase, but also some additional layout-parameters:

  • the indentation
  • the alignment of the text
    Example:
Paragraph p = new Paragraph("This is a paragraph", 
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));

[中]Paragraph是一系列的Chunk和/或[$2$]。
ParagraphPhrase具有相同的品质,但也有一些额外的布局参数:
*压痕
*文本的对齐
示例:

Paragraph p = new Paragraph("This is a paragraph", 
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));

代码示例

代码示例来源:origin: youseries/ureport

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;
  }
}

代码示例来源:origin: org.arrahtec/osdq-core

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();
  }

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * Adds a new line to the currentParagraph.
 * @since 5.0.6
 */
public void newLine() {
  if (currentParagraph == null) {
    currentParagraph = new Paragraph();
  }
  currentParagraph.add(createChunk("\n"));
}

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * Creates a shallow clone of the Paragraph.
 * @return
 */
public Paragraph cloneShallow(boolean spacingBefore) {
  Paragraph copy = new Paragraph();
  populateProperties(copy, spacingBefore);
  return copy;
}

代码示例来源:origin: com.itextpdf/itextpdf

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());
}

代码示例来源:origin: com.itextpdf/itextg

/**
 * 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);
  }
}

代码示例来源:origin: com.github.dandelion/datatables-export-itext

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);
}

代码示例来源:origin: org.technbolts/gutenberg

@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);
}

代码示例来源:origin: org.technbolts/gutenberg

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);
  }
}

代码示例来源:origin: org.technbolts/gutenberg

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;
}

代码示例来源:origin: org.technbolts.tzatziki/tzatziki-pdf

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);

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * 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;
}

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * 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;
  }
}

代码示例来源:origin: com.itextpdf/itextg

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) {

代码示例来源:origin: com.itextpdf/itextpdf

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 :

代码示例来源:origin: org.technbolts.tzatziki/tzatziki-pdf

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;
}

代码示例来源:origin: timurstrekalov/saga

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());
}

代码示例来源:origin: org.technbolts/gutenberg

@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);
  }
}

代码示例来源:origin: com.centurylink.mdw/mdw-common

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);
  }
}

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * Constructs a new <CODE>Section</CODE>.
 */
protected Section() {
  title = new Paragraph();
  numberDepth = 1;
  title.setRole(new PdfName("H" + numberDepth));
}

相关文章