All docs
V21.2
21.2
21.1
The page you are viewing does not exist in version 21.1. This link will take you to the root page.
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

PdfFreeTextAnnotationFacade Class

Contains members used to manage free text annotations without access to their inner structure.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v21.2.Core.dll

Declaration

public class PdfFreeTextAnnotationFacade :
    PdfMarkupAnnotationFacade

Remarks

Create Free Text Annotations

Create Text Box Annotations

The code sample below creates a free text annotation:

free text

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Define an annotation area
    PdfRectangle rectangle = new PdfRectangle(663, 526, 763, 576);

    // Create a free text annotation in this area
    PdfFreeTextAnnotationFacade freeText =
       pageFacade.AddFreeTextAnnotation(rectangle, "Free Text Annotation");

    // Specify annotation parameters
    freeText.Author = "Nancy Davolio";
    freeText.BorderWidth = 2;

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Create Callout Annotations

Call a free text annotation’s SetCallout method to add a callout line to the annotation. The method call sets the annotation’s Intent property to FreeTextCallout.

The code sample below creates a callout annotation pointed at a specific phrase:

callout

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    PdfRectangle calloutRectangle;

    // Find the target phrase in the document
    string calloutText = "Evaluation";
    PdfTextSearchResults searchResults = processor.FindText(calloutText);

    if (searchResults.Status == PdfTextSearchStatus.Found)
    {
        // Obtain the target phrase rectangle
        calloutRectangle = searchResults.Rectangles[0].BoundingRectangle;

        // Define an annotation area
        PdfRectangle rectangle = new PdfRectangle(663, 526, 763, 576);

        // Create a free text annotation in this area
        PdfFreeTextAnnotationFacade freeText =
            pageFacade.AddFreeTextAnnotation(rectangle, "Free Text Annotation");

        // Specify annotation parameters
        freeText.Author = "Nancy Davolio";

        // Add a callout line pointed at the center of the target phrase
        freeText.SetCallout(PdfAnnotationLineEndingStyle.OpenArrow, calloutRectangle.Center);
    }

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Create Typewriter Annotations

Set a free text annotation’s Intent property to FreeTextTypewriter to convert the annotation to a typewriter (click-to-type) object. This object has no border, callout line, or padding between the text and annotation bounds.

The code sample below creates a typewriter annotation:

typewriter annotation

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Define an annotation area
    PdfRectangle rectangle = new PdfRectangle(663, 526, 763, 576);

    // Create a free text annotation
    PdfFreeTextAnnotationFacade freeText =
        pageFacade.AddFreeTextAnnotation(rectangle, "Free Text Annotation");

    // Specify annotation parameters
    freeText.Author = "Nancy Davolio";
    freeText.Intent = PdfFreeTextAnnotationIntent.FreeTextTypewriter;

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Edit Free Text Annotations

The PdfPageFacade.Annotations property returns all page annotation properties. You can filter free text annotation properties, cast them to the PdfFreeTextAnnotationFacade class, and use class properties to modify annotation parameters.

Important

You cannot change the font name, size, and style of a free text annotation.

The code sample below changes border parameters for all free text annotations:

free text edited

using DevExpress.Pdf;
using System.Linq;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all free text annotations
    var freeTextAnnotations = pageFacade.Annotations.Where
            (annotation => annotation.Type == PdfAnnotationType.FreeText);
    foreach (PdfFreeTextAnnotationFacade freeText in freeTextAnnotations) 
    {
        // Change the color and border parameters
        freeText.InteriorColor = new PdfRGBColor(0.90, 0.00, 0.30);
        freeText.BorderWidth = 2;
        freeText.BorderStyle = PdfBorderStyle.Dash;
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Flatten Free Text Annotations

Call one of the following methods to flatten an annotation:

Method Description
PdfDocumentFacade.FlattenAnnotations Flattens document annotations.
PdfPageFacade.FlattenAnnotations Flattens annotations of a specific page.
PdfAnnotationFacade.Flatten() Flattens a specific annotation.

The code sample below flattens all free text annotations on the first page:

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Flatten all free text annotations
    page.FlattenAnnotations(PdfAnnotationType.FreeText);
}

Remove Free Text Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all free text annotations from the first page:

using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{

  // Load a document
  processor.LoadDocument("..\\..\\Document.pdf");

  // Access the first page properties
  PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

  // Retrieve all free text annotations
  var freeTextAnnotations = page.Annotations.Where
    (annotation => annotation.Type == PdfAnnotationType.FreeText).ToList();

  // Remove all free text annotations
  foreach (PdfFreeTextAnnotationFacade freeText in freeTextAnnotations)
  {
      freeText.Remove();
  }
}

Inheritance

See Also