officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addtextmarkupannotation-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-pdf-dot-pdfquadrilateral-devexpress-dot-pdf-dot-pdftextmarkupannotationtype-x29.md
Creates a text markup annotation at the specified page area.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public PdfTextMarkupAnnotationFacade AddTextMarkupAnnotation(
IEnumerable<PdfQuadrilateral> quads,
PdfTextMarkupAnnotationType style
)
Public Function AddTextMarkupAnnotation(
quads As IEnumerable(Of PdfQuadrilateral),
style As PdfTextMarkupAnnotationType
) As PdfTextMarkupAnnotationFacade
| 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.
|
| Type | Description |
|---|---|
| PdfTextMarkupAnnotationFacade |
An object that contain text markup annotation properties.
|
This method returns null if the PdfQuadrilateral object collection is empty.
The code sample below highlights document area selected in the WinForms PDF Viewer:
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);
}
Public Sub New()
InitializeComponent()
pdfViewer1.LoadDocument(filePath)
AddHandler pdfViewer1.MouseDown, AddressOf pdfViewer1_MouseDown
AddHandler pdfViewer1.MouseUp, AddressOf pdfViewer1_MouseUp
End Sub
Private startSelectionPosition As PdfDocumentPosition
Private Sub pdfViewer1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
' Get the start position of the selection
startSelectionPosition = pdfViewer1.GetDocumentPosition(e.Location, True)
If startSelectionPosition Is Nothing Then
Return
End If
End Sub
Private Sub pdfViewer1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
' Retrieve the end position of the selection
Dim endSelectionPosition As PdfDocumentPosition = pdfViewer1.GetDocumentPosition(e.Location)
If endSelectionPosition Is Nothing OrElse startSelectionPosition Is Nothing Then
Return
End If
If endSelectionPosition.Point.Equals(startSelectionPosition.Point) Then
Return
End If
' Define the points to build a quadrilateral
Dim p1 As PdfPoint = startSelectionPosition.Point
Dim p4 As PdfPoint = endSelectionPosition.Point
Dim p2 As New PdfPoint(p4.X, p1.Y)
Dim p3 As New PdfPoint(p1.X, p4.Y)
Dim pageNumber As Integer = startSelectionPosition.PageNumber
' Create a list of quadrilaterals used
' as annotation bounds
Dim annotationBounds As New List(Of PdfQuadrilateral)()
Dim quadrilateral As New PdfQuadrilateral(p1, p2, p3, p4)
annotationBounds.Add(quadrilateral)
' Add a text markup annotation
Dim pageFacade As PdfPageFacade = pdfViewer1.GetDocumentFacade().Pages(pageNumber-1)
pageFacade.AddTextMarkupAnnotation(annotationBounds, PdfTextMarkupAnnotationType.Highlight)
End Sub
See Also