Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfPageFacade.AddTextMarkupAnnotation(IEnumerable<PdfQuadrilateral>, PdfTextMarkupAnnotationType) Method

Creates a text markup annotation at the specified page area.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Core

#Declaration

#Parameters

Name Type Description
quads IEnumerable<PdfQuadrilateral>

A collection of quadrilaterals used to specify the text markup annotation bounds.

style PdfTextMarkupAnnotationType

The text markup annotation type.

#Returns

Type Description
PdfTextMarkupAnnotationFacade

An object that contain text markup annotation properties.

#Remarks

This method returns null if the PdfQuadrilateral object collection is empty.

#Example: Highlight Document Area

The code sample below highlights document area selected in the WinForms PDF Viewer:

result

public Form1()
{
    InitializeComponent();
    pdfViewer1.LoadDocument(filePath);
    pdfViewer1.MouseDown += pdfViewer1_MouseDown;
    pdfViewer1.MouseUp += pdfViewer1_MouseUp;
}

PdfDocumentPosition startSelectionPosition;
void pdfViewer1_MouseDown(object sender, MouseEventArgs e)
{
    // Get the start position of the selection
    startSelectionPosition = pdfViewer1.GetDocumentPosition(e.Location, true);
    if (startSelectionPosition == null) return;
}

void pdfViewer1_MouseUp(object sender, MouseEventArgs e)
{
    // Retrieve the end position of the selection
    PdfDocumentPosition endSelectionPosition = pdfViewer1.GetDocumentPosition(e.Location);
    if (endSelectionPosition == null || startSelectionPosition == null) return;
    if (endSelectionPosition.Point.Equals(startSelectionPosition.Point)) return;

    // Define the points to build a quadrilateral
    PdfPoint p1 = startSelectionPosition.Point;
    PdfPoint p4 = endSelectionPosition.Point;
    PdfPoint p2 = new PdfPoint(p4.X, p1.Y);
    PdfPoint p3 = new PdfPoint(p1.X, p4.Y);
    int pageNumber = startSelectionPosition.PageNumber;

    // Create a list of quadrilaterals used
    // as annotation bounds
    List<PdfQuadrilateral> annotationBounds = new List<PdfQuadrilateral>();
    PdfQuadrilateral quadrilateral = new PdfQuadrilateral(p1, p2, p3, p4);
    annotationBounds.Add(quadrilateral);

    // Add a text markup annotation
    PdfPageFacade pageFacade = pdfViewer1.GetDocumentFacade().Pages[pageNumber-1];
    pageFacade.AddTextMarkupAnnotation(annotationBounds, PdfTextMarkupAnnotationType.Highlight);
}
See Also