Class Paragraph

All Implemented Interfaces:
Indentable, Spaceable, Element, IAccessibleElement, TextElementArray, Serializable, Cloneable, Iterable<Element>, Collection<Element>, List<Element>, RandomAccess, SequencedCollection<Element>
Direct Known Subclasses:
ListItem

public class Paragraph extends Phrase implements Indentable, Spaceable, IAccessibleElement
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)));
 
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • alignment

      protected int alignment
      The alignment of the text.
    • indentationLeft

      protected float indentationLeft
      The indentation of this paragraph on the left side.
    • indentationRight

      protected float indentationRight
      The indentation of this paragraph on the right side.
    • firstLineIndent

      private float firstLineIndent
      Holds value of property firstLineIndent.
    • spacingBefore

      protected float spacingBefore
      The spacing before the paragraph.
    • spacingAfter

      protected float spacingAfter
      The spacing after the paragraph.
    • extraParagraphSpace

      private float extraParagraphSpace
      Holds value of property extraParagraphSpace.
    • keeptogether

      protected boolean keeptogether
      Does the paragraph has to be kept together on 1 page.
    • paddingTop

      protected float paddingTop
    • role

      protected PdfName role
    • accessibleAttributes

      protected HashMap<PdfName,PdfObject> accessibleAttributes
    • id

      protected AccessibleElementId id
  • Constructor Details

    • Paragraph

      public Paragraph()
      Constructs a Paragraph.
    • Paragraph

      public Paragraph(float leading)
      Constructs a Paragraph with a certain leading.
      Parameters:
      leading - the leading
    • Paragraph

      public Paragraph(Chunk chunk)
      Constructs a Paragraph with a certain Chunk.
      Parameters:
      chunk - a Chunk
    • Paragraph

      public Paragraph(float leading, Chunk chunk)
      Constructs a Paragraph with a certain Chunk and a certain leading.
      Parameters:
      leading - the leading
      chunk - a Chunk
    • Paragraph

      public Paragraph(String string)
      Constructs a Paragraph with a certain String.
      Parameters:
      string - a String
    • Paragraph

      public Paragraph(String string, Font font)
      Constructs a Paragraph with a certain String and a certain Font.
      Parameters:
      string - a String
      font - a Font
    • Paragraph

      public Paragraph(float leading, String string)
      Constructs a Paragraph with a certain String and a certain leading.
      Parameters:
      leading - the leading
      string - a String
    • Paragraph

      public Paragraph(float leading, String string, Font font)
      Constructs a Paragraph with a certain leading, String and Font.
      Parameters:
      leading - the leading
      string - a String
      font - a Font
    • Paragraph

      public Paragraph(Phrase phrase)
      Constructs a Paragraph with a certain Phrase.
      Parameters:
      phrase - a Phrase
  • Method Details

    • cloneShallow

      public Paragraph cloneShallow(boolean spacingBefore)
      Creates a shallow clone of the Paragraph.
      Returns:
    • populateProperties

      protected void populateProperties(Paragraph copy, boolean spacingBefore)
    • breakUp

      public List<Element> breakUp()
      Breaks this Paragraph up in different parts, separating paragraphs, lists and tables from each other.
      Returns:
    • type

      public int type()
      Gets the type of the text element.
      Specified by:
      type in interface Element
      Overrides:
      type in class Phrase
      Returns:
      a type
    • add

      public boolean add(Element o)
      Adds an Element to the Paragraph.
      Specified by:
      add in interface Collection<Element>
      Specified by:
      add in interface List<Element>
      Specified by:
      add in interface TextElementArray
      Overrides:
      add in class Phrase
      Parameters:
      o - the element to add.
      Returns:
      true is adding the object succeeded
    • setAlignment

      public void setAlignment(int alignment)
      Sets the alignment of this paragraph.
      Parameters:
      alignment - the new alignment
    • setIndentationLeft

      public void setIndentationLeft(float indentation)
      Description copied from interface: Indentable
      Sets the indentation on the left side.
      Specified by:
      setIndentationLeft in interface Indentable
      Parameters:
      indentation - the new indentation
    • setIndentationRight

      public void setIndentationRight(float indentation)
      Description copied from interface: Indentable
      Sets the indentation on the right side.
      Specified by:
      setIndentationRight in interface Indentable
      Parameters:
      indentation - the new indentation
    • setFirstLineIndent

      public void setFirstLineIndent(float firstLineIndent)
      Setter for property firstLineIndent.
      Parameters:
      firstLineIndent - New value of property firstLineIndent.
    • setSpacingBefore

      public void setSpacingBefore(float spacing)
      Description copied from interface: Spaceable
      Sets the spacing before.
      Specified by:
      setSpacingBefore in interface Spaceable
      Parameters:
      spacing - the new spacing
    • setSpacingAfter

      public void setSpacingAfter(float spacing)
      Description copied from interface: Spaceable
      Sets the spacing after.
      Specified by:
      setSpacingAfter in interface Spaceable
      Parameters:
      spacing - the new spacing
    • setKeepTogether

      public void setKeepTogether(boolean keeptogether)
      Indicates that the paragraph has to be kept together on one page.
      Parameters:
      keeptogether - true of the paragraph may not be split over 2 pages
    • getKeepTogether

      public boolean getKeepTogether()
      Checks if this paragraph has to be kept together on one page.
      Returns:
      true if the paragraph may not be split over 2 pages.
    • getAlignment

      public int getAlignment()
      Gets the alignment of this paragraph.
      Returns:
      alignment
    • getIndentationLeft

      public float getIndentationLeft()
      Description copied from interface: Indentable
      Gets the indentation on the left side.
      Specified by:
      getIndentationLeft in interface Indentable
      Returns:
      the indentation
    • getIndentationRight

      public float getIndentationRight()
      Description copied from interface: Indentable
      Gets the indentation on the right side.
      Specified by:
      getIndentationRight in interface Indentable
      Returns:
      the indentation
    • getFirstLineIndent

      public float getFirstLineIndent()
      Getter for property firstLineIndent.
      Returns:
      Value of property firstLineIndent.
    • getSpacingBefore

      public float getSpacingBefore()
      Description copied from interface: Spaceable
      Gets the spacing before.
      Specified by:
      getSpacingBefore in interface Spaceable
      Returns:
      the spacing
    • getSpacingAfter

      public float getSpacingAfter()
      Description copied from interface: Spaceable
      Gets the spacing after.
      Specified by:
      getSpacingAfter in interface Spaceable
      Returns:
      the spacing
    • getExtraParagraphSpace

      public float getExtraParagraphSpace()
      Getter for property extraParagraphSpace.
      Returns:
      Value of property extraParagraphSpace.
    • setExtraParagraphSpace

      public void setExtraParagraphSpace(float extraParagraphSpace)
      Setter for property extraParagraphSpace.
      Parameters:
      extraParagraphSpace - New value of property extraParagraphSpace.
    • spacingBefore

      @Deprecated public float spacingBefore()
      Deprecated.
      As of iText 2.1.5, replaced by getSpacingBefore(), scheduled for removal at 2.3.0
      Gets the spacing before this paragraph.
      Returns:
      the spacing
    • spacingAfter

      @Deprecated public float spacingAfter()
      Deprecated.
      As of iText 2.1.5, replaced by getSpacingAfter(), scheduled for removal at 2.3.0
      Gets the spacing after this paragraph.
      Returns:
      the spacing
    • getAccessibleAttribute

      public PdfObject getAccessibleAttribute(PdfName key)
      Description copied from interface: IAccessibleElement
      Get the attribute of accessible element (everything in A dictionary + Lang, Alt, ActualText, E).
      Specified by:
      getAccessibleAttribute in interface IAccessibleElement
      Parameters:
      key -
      Returns:
    • setAccessibleAttribute

      public void setAccessibleAttribute(PdfName key, PdfObject value)
      Description copied from interface: IAccessibleElement
      Set the attribute of accessible element (everything in A dictionary + Lang, Alt, ActualText, E).
      Specified by:
      setAccessibleAttribute in interface IAccessibleElement
      Parameters:
      key -
      value -
    • getAccessibleAttributes

      public HashMap<PdfName,PdfObject> getAccessibleAttributes()
      Description copied from interface: IAccessibleElement
      Gets all the properties of accessible element.
      Specified by:
      getAccessibleAttributes in interface IAccessibleElement
      Returns:
    • getRole

      public PdfName getRole()
      Description copied from interface: IAccessibleElement
      Gets the role of the accessible element.
      Specified by:
      getRole in interface IAccessibleElement
      Returns:
    • setRole

      public void setRole(PdfName role)
      Description copied from interface: IAccessibleElement
      Sets the role of the accessiblee element. Set role to null if you don't want to tag this element. Note that all child elements won't also be tagged.
      Specified by:
      setRole in interface IAccessibleElement
      Parameters:
      role -
    • getId

      public AccessibleElementId getId()
      Specified by:
      getId in interface IAccessibleElement
    • setId

      public void setId(AccessibleElementId id)
      Specified by:
      setId in interface IAccessibleElement
    • isInline

      public boolean isInline()
      Specified by:
      isInline in interface IAccessibleElement
    • getPaddingTop

      public float getPaddingTop()
      Specified by:
      getPaddingTop in interface Spaceable
    • setPaddingTop

      public void setPaddingTop(float paddingTop)
      Specified by:
      setPaddingTop in interface Spaceable