[]
        
(Showing Draft Content)

Caret Annotation

Caret annotation is a visual symbol typically used to mark text for some changes or to indicate some missing text. DsPdf provides CaretAnnotation class that allows a user to add Caret annotations to the PDF file.

DsPdf demonstrating how to add caret annotation in a PDF document

Refer to the following example code to add a caret annotation to a PDF document:

// Initialize GcPdfDocument.
GcPdfDocument doc = new GcPdfDocument();

// Create a file stream.
FileStream fs = new FileStream("Wetlands.pdf", FileMode.Open, FileAccess.Read);

// Load the file stream.
doc.Load(fs);

// Get the first page.
var page = doc.Pages[0];
            
// Get the text map.
var tm = page.GetTextMap();

// Insert the CaretAnnotation after "The Importance" text.
tm.FindText(new FindTextParams("The Importance", false, true), (fp_) =>
{
    // r is bounds of the found text.
    var r = fp_.Bounds[0].ToRect();
    // Create the CaretAnnotation and add it to the page.
    CaretAnnotation ca = new CaretAnnotation();
    ca.Page = page;
    // in this code annotation size is hardcoded, you can make a code
    // which will adjust size of the annotation depending on height of the found text fragment
    ca.Rect = new System.Drawing.RectangleF(r.Right - 4, r.Bottom - 8, 8, 8);
    ca.Opacity = 1f;
    ca.Color = Color.Red;
    ca.Contents = "This is Caret annotation.";
});

doc.Save("CaretAnnotation.pdf");