Package com.itextpdf.text
Class Section
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Element>
-
- com.itextpdf.text.Section
-
- All Implemented Interfaces:
Indentable
,Element
,LargeElement
,IAccessibleElement
,TextElementArray
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<Element>
,java.util.Collection<Element>
,java.util.List<Element>
,java.util.RandomAccess
- Direct Known Subclasses:
Chapter
public class Section extends java.util.ArrayList<Element> implements TextElementArray, LargeElement, Indentable, IAccessibleElement
ASection
is a part of aDocument
containing otherSection
s,Paragraph
s,List
and/orTable
s.Remark: you can not construct a
Section
yourself. You will have to ask an instance ofSection
to theChapter
orSection
to which you want to add the newSection
.Example:
Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255))); Chapter chapter2 = new Chapter(title2, 2); Paragraph someText = new Paragraph("This is some text"); chapter2.add(someText); Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0))); Section section1 = chapter2.addSection(title21); Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section."); section1.add(someSectionText); Paragraph title211 = new Paragraph("This is SubSection 1 in Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, new Color(255, 0, 0))); Section section11 = section1.addSection(40, title211, 2); section11.add(someSectionText);
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
addedCompletely
Indicates if the Section was added completely to the document.protected boolean
bookmarkOpen
false if the bookmark children are not visibleprotected java.lang.String
bookmarkTitle
The bookmark title if different from the content titleprotected boolean
complete
Indicates if the Section will be complete once added to the document.protected float
indentation
The additional indentation of the content of this section.protected float
indentationLeft
The indentation of this section on the left side.protected float
indentationRight
The indentation of this section on the right side.protected boolean
notAddedYet
Indicates if this is the first time the section was added.protected int
numberDepth
The number of sectionnumbers that has to be shown before the section title.protected java.util.ArrayList<java.lang.Integer>
numbers
This is the complete list of sectionnumbers of this section and the parents of this section.protected int
numberStyle
The style for sectionnumbers.static int
NUMBERSTYLE_DOTTED
A possible number style.static int
NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT
A possible number style.private static long
serialVersionUID
A serial version uid.protected int
subsections
This is the number of subsections.protected Paragraph
title
The title of this section.protected boolean
triggerNewPage
true if the section has to trigger a new page-
Fields inherited from interface com.itextpdf.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, BODY, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, DIV, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LANGUAGE, LIST, LISTITEM, MARKED, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, Element element)
Adds aParagraph
,List
orTable
to thisSection
.boolean
add(Element element)
Adds aParagraph
,List
,Table
or anotherSection
to thisSection
.boolean
addAll(java.util.Collection<? extends Element> collection)
Adds a collection ofElement
s to thisSection
.protected MarkedSection
addMarkedSection()
Adds a marked section.Section
addSection(float indentation, Paragraph title)
Creates aSection
, adds it to thisSection
and returns it.Section
addSection(float indentation, Paragraph title, int numberDepth)
Creates aSection
, adds it to thisSection
and returns it.Section
addSection(float indentation, java.lang.String title)
Adds aSection
to thisSection
and returns it.Section
addSection(float indentation, java.lang.String title, int numberDepth)
Adds aSection
to thisSection
and returns it.Section
addSection(Paragraph title)
Creates aSection
, adds it to thisSection
and returns it.Section
addSection(Paragraph title, int numberDepth)
Creates aSection
, add it to thisSection
and returns it.Section
addSection(java.lang.String title)
Adds aSection
to thisSection
and returns it.Section
addSection(java.lang.String title, int numberDepth)
Adds aSection
to thisSection
and returns it.static Paragraph
constructTitle(Paragraph title, java.util.ArrayList<java.lang.Integer> numbers, int numberDepth, int numberStyle)
Constructs a Paragraph that will be used as title for a Section or Chapter.void
flushContent()
Flushes the content that has been added.PdfObject
getAccessibleAttribute(PdfName key)
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).java.util.HashMap<PdfName,PdfObject>
getAccessibleAttributes()
Gets all the properties of accessible element.Paragraph
getBookmarkTitle()
Gets the bookmark title.java.util.List<Chunk>
getChunks()
Gets all the chunks in this element.int
getDepth()
Returns the depth of this section.AccessibleElementId
getId()
float
getIndentation()
Returns the indentation of the content of thisSection
.float
getIndentationLeft()
Returns the indentation of thisSection
on the left side.float
getIndentationRight()
Returns the indentation of thisSection
on the right side.int
getNumberDepth()
Returns the numberdepth of thisSection
.int
getNumberStyle()
Gets the style used for numbering sections.PdfName
getRole()
Gets the role of the accessible element.Paragraph
getTitle()
Returns the title, preceded by a certain number of sectionnumbers.protected boolean
isAddedCompletely()
boolean
isBookmarkOpen()
Getter for property bookmarkOpen.boolean
isChapter()
Checks if this object is aChapter
.boolean
isComplete()
Indicates if the element is complete or not.boolean
isContent()
Checks if this element is a content object.boolean
isInline()
boolean
isNestable()
Checks if this element is nestable.boolean
isNotAddedYet()
Indicates if this is the first time the section is added.boolean
isSection()
Checks if this object is aSection
.boolean
isTriggerNewPage()
Getter for property bookmarkOpen.void
newPage()
Adds a new page to the section.boolean
process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.void
setAccessibleAttribute(PdfName key, PdfObject value)
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).protected void
setAddedCompletely(boolean addedCompletely)
void
setBookmarkOpen(boolean bookmarkOpen)
Setter for property bookmarkOpen.void
setBookmarkTitle(java.lang.String bookmarkTitle)
Sets the bookmark title.void
setChapterNumber(int number)
Changes the Chapter number.void
setComplete(boolean complete)
If you invoke setComplete(false), you indicate that the content of the object isn't complete yet; it can be added to the document partially, but more will follow.void
setId(AccessibleElementId id)
void
setIndentation(float indentation)
Sets the indentation of the content of thisSection
.void
setIndentationLeft(float indentation)
Sets the indentation of thisSection
on the left side.void
setIndentationRight(float indentation)
Sets the indentation of thisSection
on the right side.void
setNotAddedYet(boolean notAddedYet)
Sets the indication if the section was already added to the document.void
setNumberDepth(int numberDepth)
Sets the depth of the sectionnumbers that will be shown preceding the title.private void
setNumbers(int number, java.util.ArrayList<java.lang.Integer> numbers)
Sets the number of this section.void
setNumberStyle(int numberStyle)
Sets the style for numbering sections.void
setRole(PdfName role)
Sets the role of the accessiblee element.void
setTitle(Paragraph title)
Sets the title of this section.void
setTriggerNewPage(boolean triggerNewPage)
Setter for property triggerNewPage.int
type()
Gets the type of the text element.-
Methods inherited from class java.util.ArrayList
addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Field Detail
-
NUMBERSTYLE_DOTTED
public static final int NUMBERSTYLE_DOTTED
A possible number style. The default number style: "1.2.3."- Since:
- iText 2.0.8
- See Also:
- Constant Field Values
-
NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT
public static final int NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT
A possible number style. For instance: "1.2.3"- Since:
- iText 2.0.8
- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
A serial version uid.- See Also:
- Constant Field Values
-
title
protected Paragraph title
The title of this section.
-
bookmarkTitle
protected java.lang.String bookmarkTitle
The bookmark title if different from the content title
-
numberDepth
protected int numberDepth
The number of sectionnumbers that has to be shown before the section title.
-
numberStyle
protected int numberStyle
The style for sectionnumbers.- Since:
- iText 2.0.8
-
indentationLeft
protected float indentationLeft
The indentation of this section on the left side.
-
indentationRight
protected float indentationRight
The indentation of this section on the right side.
-
indentation
protected float indentation
The additional indentation of the content of this section.
-
bookmarkOpen
protected boolean bookmarkOpen
false if the bookmark children are not visible
-
triggerNewPage
protected boolean triggerNewPage
true if the section has to trigger a new page
-
subsections
protected int subsections
This is the number of subsections.
-
numbers
protected java.util.ArrayList<java.lang.Integer> numbers
This is the complete list of sectionnumbers of this section and the parents of this section.
-
complete
protected boolean complete
Indicates if the Section will be complete once added to the document.- Since:
- iText 2.0.8
-
addedCompletely
protected boolean addedCompletely
Indicates if the Section was added completely to the document.- Since:
- iText 2.0.8
-
notAddedYet
protected boolean notAddedYet
Indicates if this is the first time the section was added.- Since:
- iText 2.0.8
-
-
Constructor Detail
-
Section
protected Section()
Constructs a newSection
.
-
Section
protected Section(Paragraph title, int numberDepth)
Constructs a newSection
.- Parameters:
title
- aParagraph
numberDepth
- the numberDepth
-
-
Method Detail
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.
-
type
public int type()
Gets the type of the text element.
-
isChapter
public boolean isChapter()
Checks if this object is aChapter
.- Returns:
true
if it is aChapter
,false
if it is aSection
.
-
isSection
public boolean isSection()
Checks if this object is aSection
.- Returns:
true
if it is aSection
,false
if it is aChapter
.
-
getChunks
public java.util.List<Chunk> getChunks()
Gets all the chunks in this element.
-
isContent
public boolean isContent()
Description copied from interface:Element
Checks if this element is a content object. If not, it's a metadata object.- Specified by:
isContent
in interfaceElement
- Returns:
- true if this is a 'content' element; false if this is a 'metadata' element
- Since:
- iText 2.0.8
- See Also:
Element.isContent()
-
isNestable
public boolean isNestable()
Description copied from interface:Element
Checks if this element is nestable.- Specified by:
isNestable
in interfaceElement
- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
Element.isNestable()
-
add
public void add(int index, Element element)
Adds aParagraph
,List
orTable
to thisSection
.- Specified by:
add
in interfacejava.util.List<Element>
- Overrides:
add
in classjava.util.ArrayList<Element>
- Parameters:
index
- index at which the specified element is to be insertedelement
- an element of typeParagraph
,List
orTable
=- Throws:
java.lang.ClassCastException
- if the object is not aParagraph
,List
orTable
- Since:
- 5.0.1 (signature changed to use Element)
-
add
public boolean add(Element element)
Adds aParagraph
,List
,Table
or anotherSection
to thisSection
.- Specified by:
add
in interfacejava.util.Collection<Element>
- Specified by:
add
in interfacejava.util.List<Element>
- Specified by:
add
in interfaceTextElementArray
- Overrides:
add
in classjava.util.ArrayList<Element>
- Parameters:
element
- an element of typeParagraph
,List
,Table
or anotherSection
- Returns:
- a boolean
- Throws:
java.lang.ClassCastException
- if the object is not aParagraph
,List
,Table
orSection
- Since:
- 5.0.1 (signature changed to use Element)
-
addAll
public boolean addAll(java.util.Collection<? extends Element> collection)
Adds a collection ofElement
s to thisSection
.- Specified by:
addAll
in interfacejava.util.Collection<Element>
- Specified by:
addAll
in interfacejava.util.List<Element>
- Overrides:
addAll
in classjava.util.ArrayList<Element>
- Parameters:
collection
- a collection ofParagraph
s,List
s and/orTable
s- Returns:
true
if the action succeeded,false
if not.- Throws:
java.lang.ClassCastException
- if one of the objects isn't aParagraph
,List
,Table
-
addSection
public Section addSection(float indentation, Paragraph title, int numberDepth)
Creates aSection
, adds it to thisSection
and returns it.- Parameters:
indentation
- the indentation of the new sectiontitle
- the title of the new sectionnumberDepth
- the numberDepth of the section- Returns:
- a new Section object
-
addSection
public Section addSection(float indentation, Paragraph title)
Creates aSection
, adds it to thisSection
and returns it.- Parameters:
indentation
- the indentation of the new sectiontitle
- the title of the new section- Returns:
- a new Section object
-
addSection
public Section addSection(Paragraph title, int numberDepth)
Creates aSection
, add it to thisSection
and returns it.- Parameters:
title
- the title of the new sectionnumberDepth
- the numberDepth of the section- Returns:
- a new Section object
-
addMarkedSection
protected MarkedSection addMarkedSection()
Adds a marked section. For use in class MarkedSection only!- Returns:
- the MarkedSection
-
addSection
public Section addSection(Paragraph title)
Creates aSection
, adds it to thisSection
and returns it.- Parameters:
title
- the title of the new section- Returns:
- a new Section object
-
addSection
public Section addSection(float indentation, java.lang.String title, int numberDepth)
Adds aSection
to thisSection
and returns it.- Parameters:
indentation
- the indentation of the new sectiontitle
- the title of the new sectionnumberDepth
- the numberDepth of the section- Returns:
- a new Section object
-
addSection
public Section addSection(java.lang.String title, int numberDepth)
Adds aSection
to thisSection
and returns it.- Parameters:
title
- the title of the new sectionnumberDepth
- the numberDepth of the section- Returns:
- a new Section object
-
addSection
public Section addSection(float indentation, java.lang.String title)
Adds aSection
to thisSection
and returns it.- Parameters:
indentation
- the indentation of the new sectiontitle
- the title of the new section- Returns:
- a new Section object
-
addSection
public Section addSection(java.lang.String title)
Adds aSection
to thisSection
and returns it.- Parameters:
title
- the title of the new section- Returns:
- a new Section object
-
setTitle
public void setTitle(Paragraph title)
Sets the title of this section.- Parameters:
title
- the new title
-
getTitle
public Paragraph getTitle()
Returns the title, preceded by a certain number of sectionnumbers.- Returns:
- a
Paragraph
-
constructTitle
public static Paragraph constructTitle(Paragraph title, java.util.ArrayList<java.lang.Integer> numbers, int numberDepth, int numberStyle)
Constructs a Paragraph that will be used as title for a Section or Chapter.- Parameters:
title
- the title of the sectionnumbers
- a list of sectionnumbersnumberDepth
- how many numbers have to be shownnumberStyle
- the numbering style- Returns:
- a Paragraph object
- Since:
- iText 2.0.8
-
setNumberDepth
public void setNumberDepth(int numberDepth)
Sets the depth of the sectionnumbers that will be shown preceding the title.If the numberdepth is 0, the sections will not be numbered. If the numberdepth is 1, the section will be numbered with their own number. If the numberdepth is higher (for instance x > 1), the numbers of x - 1 parents will be shown.
- Parameters:
numberDepth
- the new numberDepth
-
getNumberDepth
public int getNumberDepth()
Returns the numberdepth of thisSection
.- Returns:
- the numberdepth
-
setNumberStyle
public void setNumberStyle(int numberStyle)
Sets the style for numbering sections. Possible values areNUMBERSTYLE_DOTTED
: 1.2.3. (the default) orNUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT
: 1.2.3- Parameters:
numberStyle
- the style to use- Since:
- iText 2.0.8
-
getNumberStyle
public int getNumberStyle()
Gets the style used for numbering sections.- Returns:
- a value corresponding with a numbering style
- Since:
- iText 2.0.8
-
setIndentationLeft
public void setIndentationLeft(float indentation)
Sets the indentation of thisSection
on the left side.- Specified by:
setIndentationLeft
in interfaceIndentable
- Parameters:
indentation
- the indentation
-
getIndentationLeft
public float getIndentationLeft()
Returns the indentation of thisSection
on the left side.- Specified by:
getIndentationLeft
in interfaceIndentable
- Returns:
- the indentation
-
setIndentationRight
public void setIndentationRight(float indentation)
Sets the indentation of thisSection
on the right side.- Specified by:
setIndentationRight
in interfaceIndentable
- Parameters:
indentation
- the indentation
-
getIndentationRight
public float getIndentationRight()
Returns the indentation of thisSection
on the right side.- Specified by:
getIndentationRight
in interfaceIndentable
- Returns:
- the indentation
-
setIndentation
public void setIndentation(float indentation)
Sets the indentation of the content of thisSection
.- Parameters:
indentation
- the indentation
-
getIndentation
public float getIndentation()
Returns the indentation of the content of thisSection
.- Returns:
- the indentation
-
setBookmarkOpen
public void setBookmarkOpen(boolean bookmarkOpen)
Setter for property bookmarkOpen.- Parameters:
bookmarkOpen
- false if the bookmark children are not visible.
-
isBookmarkOpen
public boolean isBookmarkOpen()
Getter for property bookmarkOpen.- Returns:
- Value of property bookmarkOpen.
-
setTriggerNewPage
public void setTriggerNewPage(boolean triggerNewPage)
Setter for property triggerNewPage.- Parameters:
triggerNewPage
- true if a new page has to be triggered.
-
isTriggerNewPage
public boolean isTriggerNewPage()
Getter for property bookmarkOpen.- Returns:
- Value of property triggerNewPage.
-
setBookmarkTitle
public void setBookmarkTitle(java.lang.String bookmarkTitle)
Sets the bookmark title. The bookmark title is the same as the section title but can be changed with this method.- Parameters:
bookmarkTitle
- the bookmark title
-
getBookmarkTitle
public Paragraph getBookmarkTitle()
Gets the bookmark title.- Returns:
- the bookmark title
-
setChapterNumber
public void setChapterNumber(int number)
Changes the Chapter number.- Parameters:
number
- the new number
-
getDepth
public int getDepth()
Returns the depth of this section.- Returns:
- the depth
-
setNumbers
private void setNumbers(int number, java.util.ArrayList<java.lang.Integer> numbers)
Sets the number of this section.- Parameters:
number
- the number of this sectionnumbers
- anArrayList
, containing the numbers of the Parent
-
isNotAddedYet
public boolean isNotAddedYet()
Indicates if this is the first time the section is added.- Returns:
- true if the section wasn't added yet
- Since:
- iText2.0.8
-
setNotAddedYet
public void setNotAddedYet(boolean notAddedYet)
Sets the indication if the section was already added to the document.- Parameters:
notAddedYet
-- Since:
- iText2.0.8
-
isAddedCompletely
protected boolean isAddedCompletely()
- Returns:
- return the addedCompletely value
- Since:
- iText 2.0.8
-
setAddedCompletely
protected void setAddedCompletely(boolean addedCompletely)
- Parameters:
addedCompletely
- true if section was completely added, false otherwise- Since:
- iText 2.0.8
-
flushContent
public void flushContent()
Description copied from interface:LargeElement
Flushes the content that has been added.- Specified by:
flushContent
in interfaceLargeElement
- Since:
- iText 2.0.8
- See Also:
LargeElement.flushContent()
-
isComplete
public boolean isComplete()
Description copied from interface:LargeElement
Indicates if the element is complete or not.- Specified by:
isComplete
in interfaceLargeElement
- Returns:
- indicates if the element is complete according to the user.
- Since:
- iText 2.0.8
- See Also:
LargeElement.isComplete()
-
setComplete
public void setComplete(boolean complete)
Description copied from interface:LargeElement
If you invoke setComplete(false), you indicate that the content of the object isn't complete yet; it can be added to the document partially, but more will follow. If you invoke setComplete(true), you indicate that you won't add any more data to the object.- Specified by:
setComplete
in interfaceLargeElement
- Parameters:
complete
- false if you'll be adding more data after adding the object to the document.- Since:
- iText 2.0.8
- See Also:
LargeElement.setComplete(boolean)
-
newPage
public void newPage()
Adds a new page to the section.- Since:
- 2.1.1
-
getAccessibleAttribute
public PdfObject getAccessibleAttribute(PdfName key)
Description copied from interface:IAccessibleElement
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
getAccessibleAttribute
in interfaceIAccessibleElement
- Returns:
-
setAccessibleAttribute
public void setAccessibleAttribute(PdfName key, PdfObject value)
Description copied from interface:IAccessibleElement
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
setAccessibleAttribute
in interfaceIAccessibleElement
-
getAccessibleAttributes
public java.util.HashMap<PdfName,PdfObject> getAccessibleAttributes()
Description copied from interface:IAccessibleElement
Gets all the properties of accessible element.- Specified by:
getAccessibleAttributes
in interfaceIAccessibleElement
- Returns:
-
getRole
public PdfName getRole()
Description copied from interface:IAccessibleElement
Gets the role of the accessible element.- Specified by:
getRole
in interfaceIAccessibleElement
- Returns:
-
setRole
public void setRole(PdfName role)
Description copied from interface:IAccessibleElement
Sets the role of the accessiblee element. Set role tonull
if you don't want to tag this element. Note that all child elements won't also be tagged.- Specified by:
setRole
in interfaceIAccessibleElement
-
getId
public AccessibleElementId getId()
- Specified by:
getId
in interfaceIAccessibleElement
-
setId
public void setId(AccessibleElementId id)
- Specified by:
setId
in interfaceIAccessibleElement
-
isInline
public boolean isInline()
- Specified by:
isInline
in interfaceIAccessibleElement
-
-