The basic building blocks of iText7 advanced tutorial-0. Overview of classes and interfaces

    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 IElementall 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 Istarts with a letter .

    Figure 1 below shows the IElemeentrelationship with other interfaces in a macro view :

itext-h-1

Figure 1. Interface overview

    At the highest level of the entire hierarchy, we can see the IPropertyContainerinterface. This interface defines methods to set, get and delete attributes. This interface has two direct subinterfaces: IElementand IRenderr. IElementThe interface is finally implemented by some classes, for example Text, Paragraphand Table. Objects of these classes will be added to a documnt directly or indirectly. The IRendererinterface will eventually be implemented by other classes, for example TextRender, ParagraphRendererand TableRenderwhen we want to adjust the presentation of an object, these renderers will be used internally by iText.

    IElementTwo direct subinterfaces of the interface. ILeafElementThe interface will be implemented by those building block elements that cannot contain other elements. For example, you can add one Textand one Imageelement to the Paragraphobject, but you cannot add any element to one Textor Imageelement. So the Textand Imageelement implements the ILeafElementinterface. Finally, the ILeafElementinterface 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

    IPropertyContainerThe interface is ElementPropertyContainerimplemented by abstract classes . This class has three direct subclasses, as shown in Figure 2:

itext-h-2

Figure 2. Implementation of IPropertyContainer

    StyleA class is a container with many style properties, such as margins, inner margins, and rotation properties. It ElementPropertyContainerinherits some style attributes from the abstract class, such as width, height, color, border, and alignment.

    RootElementThe class defines methods to add content, either using add()methods or using showTextAligned()methods. DocumentThe object will add content to a page. The Canvasobject does not know the concept of Page. RootElementIt 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 AbstractElementimplementation class of the interface in a macro view :

itext-h-3

Figure 3. Implementation of the IElement interface

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 AbstractElementclasses must implement IElementinterfaces. Text, Image, TabAnd Linkimplement ILeafElementinterfaces. ILargeElementInterfaces will only be Tableimplemented 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, IAcesssibleElementthe 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 Tableis marked as a Table, Listis marked as a list, the remaining elements are correct with the tag, these elements include: Text, Link, Image, Paragraph, Div, List, ListItem, Celland LineSeparator. TabAnd AreaBreakobjects will not implement the IAcesssibleElementinterface because they have no actual content and spaces have no semantics.

IRender implementation class

    iText will use the correct s IRenderto render the content in the document. Figure 4 below shows IRenderthe implementation class of the interface:

itext-h-4

Figure 4. Implementation of the IRender interface

    Let’s compare this picture with the previous picture. We will find that each AbstractElementand each RootElementhas a corresponding renderer. We will not discuss each renderer in depth here. In the following examples, we will refer to these renderers. , Mentioned later

Guess you like

Origin blog.csdn.net/u012397189/article/details/79834501