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
public PdfTextMarkupAnnotationFacade AddTextMarkupAnnotation(
IEnumerable<PdfQuadrilateral> quads,
PdfTextMarkupAnnotationType style
)
#Parameters
Name | Type | Description |
---|---|---|
quads | IEnumerable<Pdf |
A collection of quadrilaterals used to specify the text markup annotation bounds. |
style | Pdf |
The text markup annotation type. |
#Returns
Type | Description |
---|---|
Pdf |
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:
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