Text annotation represents a sticky note attached to a point in a PDF file. Upon closing, the annotation appears as an icon, and upon opening, it displays a pop-up window with the text of the note in the size and font selected by the viewer application. DsPdf provides TextAnnotation class to enable users to apply text annotations to the PDF document.
TextAnnotation class provides the following properties to set various options for the text annotation:
Property | Description |
---|---|
UserName | Adds the user name to the text label in the title bar of the annotation’s pop-up window when the annotation is open and active. |
Subject | Adds the text representing the subject of the annotation. |
Contents | Adds the text to the annotation for display. |
RichText | Adds the text to the annotation for display in the pop-up window when opened. You can format this text using HTML tags. |
Opacity | Sets the opacity of the annotation. |
Color | Sets the annotation color, popup window color, line color, etc. |
Icon | Sets the type of the icon to display the annotation. |
Open | Sets a flag specifying whether the annotation should initially be displayed open. |
State | Sets the state of original annotation. |
StateModel | Sets the state model corresponding to State. |
PdfRect | Sets the rectangle that defines the location and size of the annotation on a page in PDF user space coordinates. The positive X axis extends horizontally to the right, and the positive Y axis extends vertically upward, with the origin usually in the lower left corner of the page. |
Refer to the following example code to add a text annotation to a PDF document:
C# |
Copy Code
|
---|---|
public void CreateTextAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 200, 50); page.Graphics.DrawString("A red text annotation initially open is placed to the right of this note.", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of TextAnnotation class and set its relevant properties var textAnnot = new TextAnnotation() { UserName = "Jamie Smith", Contents = "This is a text annotation in red color.", PdfRect = new RectangleF(rc.Right, rc.Top, 72 * 2, 72), Color = Color.Red, Open = true }; page.Annotations.Add(textAnnot); //Add the text annotation doc.Save("TextAnnotation.pdf"); } |