Document Solutions for PDF
Features / Annotations / Square Annotation
In This Topic
    Square Annotation
    In This Topic

    A square annotation displays a rectangle or square on the page. When opened, the annotation displays a pop-up window with the text of the associated note. DsPdf provides SquareAnnotation class to enable users to apply square annotations to the PDF file.

    Note that a square annotation does not always imply that the annotation is square in shape. The height and width of the annotation may vary. The image given below depicts a rectangle-shaped square annotation.

    Square annotation in a PDF file

    SquareAnnotation class provides the following properties to set various options for the square 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.
    FillColor Sets the fill color.
    LineWidth Sets the line width in points.
    LineDashPattern Sets the border line pattern to a dash pattern. Null means a solid line.
    Color Sets the annotation color, popup window color, line color, etc.
    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 square annotation to a PDF document:

    C#
    Copy Code
    public void CreateSquareAnnotation()
    {
        GcPdfDocument doc = new GcPdfDocument();
        Page page = doc.NewPage();
        RectangleF rc = new RectangleF(50, 50, 250, 50);
        page.Graphics.DrawString
            ("A square annotation drawn with a 3pt wide orange line around this note has a rich text " +
            "associated with it.",
            new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); rc.Inflate(10, 10);
    
        //Create an instance of SquareAnnotation class and set its relevant properties
        var squareAnnot = new SquareAnnotation()
        {
            UserName = "Jaime Smith",
            PdfRect = rc,
            LineWidth = 3,
            Color = Color.Orange,
            RichText =
      "<body><p>This <b><i>rich text</i></b> is associated with the square annotation around a text note.</p></body>"
        };
        page.Annotations.Add(squareAnnot); //Add the square annotation
        doc.Save("SquareAnnotation.pdf");
    }