IText supports different types of annotations.
Text: You can add a small piece of text to a document. This text is not part of the document content and has a title and some text content.
Annotation a = new Annotation (
"Authors ",
"Maybe it's because I wanted to be an author myself that I wrote iText .");
External link: when using external links as comments, you must specify a rectangular area and a string (the string is the URL of the target to be linked) or a URL object. The following is a demonstration of using strings and URL objects.
Annotation annot = new Annotation (100f, 700f, 200f, 800f, new URL ("http://www.cmszs.com "));
Annotation annot = new Annotation (100f, 700f, 200f, 800f, "http://www.cmszs.com ");
External PDF file: when using a PDF file as a comment, you must specify a rectangular area and target PDF file, a page linked to the file, or a target defined in the Link PDF file. The example is as follows:
Annotation annot = new Annotation (100f, 700f, 200f, 800f, "otheration", "mark ");
Annotation annot = new Annotation (100f, 700f, 200f, 800f, "otheration", 2 );
Naming action: when using a naming action as a comment, you must specify a rectangular area and a naming action as a parameter. As shown below
Annotation annot = new Annotation (100f, 700f, 200f, 800f, PdfAction. FIRSTPAGE );
Application: when using an application as a comment, you must specify a rectangular area and an application name as the parameter, as shown below.
Annotation annot = new Annotation (300f, 700f, 400f, 800f, "C: // winnt/notepad.exe", null );
If you do not need to specify the comment location when adding a text comment, iText processes it internally and the comment will appear below the text you want to add the comment. Annotations of other types except text must specify the coordinates of a rectangle. In this example, we draw some squares and add comments to the square. Click here to view the results of this example.