This series begins with a comprehensive description of the building blocks in iText7 and some other applications.
This series is also translated from the official website of iText, and will also add your own personal opinions. If you don’t understand anything, you can go to the official website to view
Total interface
When we talk about the basic building blocks (that is, some page elements) in iText7, we will first mention IElement
all the classes that implement interfaces. iText7 was first written in Java and then ported to C#. For the convenience of developers, iText7 official, especially for C# developers, the name of each class interface I
starts with a letter .
Figure 1 below shows the IElemeent
relationship with other interfaces in a macro view :
At the highest level of the entire hierarchy, we can see the IPropertyContainer
interface. This interface defines methods to set, get and delete attributes. This interface has two direct subinterfaces: IElement
and IRenderr
. IElement
The interface is finally implemented by some classes, for example Text
, Paragraph
and Table
. Objects of these classes will be added to a documnt directly or indirectly. The IRenderer
interface will eventually be implemented by other classes, for example TextRender
, ParagraphRenderer
and TableRender
when we want to adjust the presentation of an object, these renderers will be used internally by iText.
IElement
Two direct subinterfaces of the interface. ILeafElement
The interface will be implemented by those building block elements that cannot contain other elements. For example, you can add one Text
and one Image
element to the Paragraph
object, but you cannot add any element to one Text
or Image
element. So the Text
and Image
element implements the ILeafElement
interface. Finally, the ILeafElement
interface here is to allow you to render the object before adding all the content. The advantage of this is to reduce memory usage: before adding all the content, the content that has been added to the table can be rendered and cleared from the memory.
Abstract class that implements the interface
IPropertyContainer
The interface is ElementPropertyContainer
implemented by abstract classes . This class has three direct subclasses, as shown in Figure 2:
Style
A class is a container with many style properties, such as margins, inner margins, and rotation properties. It ElementPropertyContainer
inherits some style attributes from the abstract class, such as width, height, color, border, and alignment.
RootElement
The class defines methods to add content, either using add()
methods or using showTextAligned()
methods. Document
The object will add content to a page. The Canvas
object does not know the concept of Page. RootElement
It is equivalent to act as a bridge and transition between the high-level layout API ( Document
) and the low-level layout API ( Canvas
).
Figure 3 below shows the AbstractElement
implementation class of the interface in a macro view :
This picture and the picture below are relatively vague, the pictures given on the official website are very vague, there is no way, you can redraw it when you have time>_<, you can see the text explanation
All inherited AbstractElement
classes must implement IElement
interfaces. Text
, Image
, Tab
And Link
implement ILeafElement
interfaces. ILargeElement
Interfaces will only be Table
implemented by classes. The use of the above-mentioned classes can make it easier to create tagged PDFs.
Do you remember the PDF/A level A I mentioned in Chapter 7, the PDF of the tagged PDF is mentioned in that chapter, if you forget, you can check it out
When we use the setTAgged()
method to create one PdfDocument
, IAcesssibleElement
the semantic information of all the elements that implement the interface will be added to the PDF file of the province. iText creates a tree structure, the tree structure which Table
is marked as a Table, List
is marked as a list, the remaining elements are correct with the tag, these elements include: Text
, Link
, Image
, Paragraph
, Div
, List
, ListItem
, Cell
and LineSeparator
. Tab
And AreaBreak
objects will not implement the IAcesssibleElement
interface because they have no actual content and spaces have no semantics.
IRender implementation class
iText will use the correct s IRender
to render the content in the document. Figure 4 below shows IRender
the implementation class of the interface:
Let’s compare this picture with the previous picture. We will find that each AbstractElement
and each RootElement
has a corresponding renderer. We will not discuss each renderer in depth here. In the following examples, we will refer to these renderers. , Mentioned later