PdfTextMarkupAnnotationFacade Class
Contains members used to manage text markup annotations (text highlights) without access to their inner structure.
Namespace: DevExpress.Pdf
Assembly: DevExpress.Pdf.v24.2.Core.dll
NuGet Package: DevExpress.Pdf.Core
#Declaration
public class PdfTextMarkupAnnotationFacade :
PdfMarkupAnnotationFacade
#Related API Members
The following members return PdfTextMarkupAnnotationFacade objects:
#Remarks
#Create Text Markup Annotations
The code sample below strikes out specific text in the document:
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
// Load a document
processor.LoadDocument("..\\..\\Document.pdf");
// Access the first page properties
PdfDocumentFacade facade = processor.DocumentFacade;
PdfPageFacade page = facade.Pages[0];
// Find the target phrase in the document
string strikeOutText = "Xbox";
PdfTextSearchResults strikeSearchResults = processor.FindText(strikeOutText);
if (strikeSearchResults.Status == PdfTextSearchStatus.Found)
{
// Add text markup annotation to this phrase
PdfTextMarkupAnnotationFacade strikeOutAnnotation =
page.AddTextMarkupAnnotation(strikeSearchResults.Rectangles[0], PdfTextMarkupAnnotationType.StrikeOut);
// Specify annotation properties
strikeOutAnnotation.Author = "Bill Smith";
strikeOutAnnotation.Subject = "Important!";
strikeOutAnnotation.Contents = "Please, fact-check this reference";
strikeOutAnnotation.Color = new PdfRGBColor(0.10, 0.85, 1.00);
}
}
#Edit Text Markup Annotations
The PdfPageFacade.Annotations property retrieves all annotations on the page. You can filter text markup annotation properties, cast them to the PdfTextMarkupAnnotationFacade class, and use class properties to modify annotation parameters.
The code sample below changes the markup type and color of all text markup annotations on 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 page = processor.DocumentFacade.Pages[0];
// Retrieve all text markup annotations
var textMarkups = page.Annotations.Where
(annotation => annotation.Type == PdfAnnotationType.TextMarkup);
// Change annotation parameters
foreach (PdfTextMarkupAnnotationFacade markup in textMarkups)
{
markup.MarkupType = PdfTextMarkupAnnotationType.Squiggly;
markup.Color = new PdfRGBColor(0.10, 0.85, 1.00);
}
// Save the result
processor.SaveDocument("..\\..\\Result.pdf");
}
#Flatten Text Markup Annotations
Call one of the following methods to flatten an annotation:
Method | Description |
---|---|
Pdf |
Flattens document annotations. |
Pdf |
Flattens annotations of a specific page. |
Pdf |
Flattens a specific annotation. |
The code sample below flattens all text markup annotations on the first page:
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
// Load a document
processor.LoadDocument("..\\..\\Document.pdf");
// Access the first page properties
PdfPageFacade page = processor.DocumentFacade.Pages[0];
// Flatten all text markups
page.FlattenAnnotations(PdfAnnotationType.TextMarkup);
// Save the result
processor.SaveDocument("..\\..\\Result.pdf");
}
#Remove Text Markup Annotations
Call the PdfAnnotationFacade.Remove() method to remove a specific annotation.
The code sample below removes all text markup annotations from the first page:
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
// Load a document
processor.LoadDocument("..\\..\\Document.pdf");
// Access the first page properties
PdfPageFacade page = processor.DocumentFacade.Pages[0];
// Retrieve all text markup annotations
var textMarkups = page.Annotations.Where
(annotation => annotation.Type == PdfAnnotationType.TextMarkup).ToList();
foreach (PdfTextMarkupAnnotationFacade markup in textMarkups)
{
// Remove each annotation
markup.Remove();
}
// Save the result
processor.SaveDocument("..\\..\\Result.pdf");
}