[]
A free text annotation displays text directly on the page. Unlike text annotations, free text annotations do not have an open or closed state. Instead of appearing in a pop-up window, the text stays visible. GcPdf provides FreeTextAnnotation class to enable users to apply free text annotations to the PDF file.
FreeTextAnnotation class provides the following properties to set various options for the free 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. |
LineDashPattern | Sets the border line pattern to a dash pattern. Null means a solid line. |
LineWidth | Sets the line width in points. |
CalloutLine | Sets an array of 2 or 3 System.Drawing.PointF structures specify a callout line attached to the free text annotation. Three points represent the starting coordinates, the knee point, and the ending coordinates of the line. Two points represent the starting and ending coordinates of the line. The coordinates are in default user space relative to the upper left corner of the page's media box, with the Y (vertical) coordinates increasing from top to bottom. |
LineEndStyle | Sets the style of the end callout line. |
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 free text annotation to a PDF document:
public void CreateFreeTextAnnotation()
{
GcPdfDocument doc = new GcPdfDocument();
Page page = doc.NewPage();
RectangleF rc = new RectangleF(50, 50, 200, 50);
page.Graphics.DrawString
("A blue free text annotation is placed below and to the right, " +
"with a callout going from it to this note",
new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc);
//Create an instance of FreeTextAnnotation class and set its relevant properties
var freeAnnot = new FreeTextAnnotation()
{
PdfRect = new RectangleF(rc.Right + 18, rc.Bottom + 9, 72 * 2, 72),
CalloutLine = new PointF[]
{
new PointF(rc.Left + rc.Width / 2, rc.Bottom),
new PointF(rc.Left + rc.Width / 2, rc.Bottom + 9 + 36),
new PointF(rc.Right + 18, rc.Bottom + 9 + 36),
},
LineWidth = 1,
LineEndStyle = LineEndingStyle.OpenArrow,
LineDashPattern = new float[] { 8, 4 },
Contents = "This is a free text annotation with a callout line going to the note on the left.",
Color = Color.LightSkyBlue,
};
page.Annotations.Add(freeAnnot); //Add the free text annotation
doc.Save("FreeTextAnnotation.pdf");
}