officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-clearcontent-x28-devexpress-dot-pdf-dot-pdfclearcontentregions-devexpress-dot-pdf-dot-pdfclearcontentoptions-x29.md
Clears the document content located in the specified regions. Allows you to set what content type to keep in these regions.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public void ClearContent(
PdfClearContentRegions regions,
PdfClearContentOptions options
)
Public Sub ClearContent(
regions As PdfClearContentRegions,
options As PdfClearContentOptions
)
| Name | Type | Description |
|---|---|---|
| regions | PdfClearContentRegions |
Page regions to clear.
| | options | PdfClearContentOptions |
Options that specify what content type to keep in target regions.
|
The code sample below removes all entries of a specific phrase from the first page;
using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
// Load a document
pdfDocumentProcessor.LoadDocument("Document.pdf");
PdfClearContentRegions contentRegions = new PdfClearContentRegions();
// Find the target phrase in the document
string removeText = "Ounce";
PdfTextSearchParameters searchParameters = new PdfTextSearchParameters()
{
WholeWords = true
};
PdfTextSearchResults searchResults = pdfDocumentProcessor.FindText(removeText, searchParameters);
while (searchResults.Status == PdfTextSearchStatus.Found && searchResults.PageNumber == 1)
{
// Add text rectangles to the region collection:
contentRegions.Add(searchResults.Rectangles);
searchResults = pdfDocumentProcessor.FindText(removeText, searchParameters);
}
// Get the first page properties
PdfPageFacade pageFacade = pdfDocumentProcessor.DocumentFacade.Pages[0];
// Specify what content type to keep in target areas
PdfClearContentOptions options = new PdfClearContentOptions()
{
ClearAnnotations = false,
ClearGraphics = false,
ClearImages = false
};
// Remove found entries
pageFacade.ClearContent(contentRegions, options);
// Save the result
pdfDocumentProcessor.SaveDocument("Document_cleared.pdf");
}
Using pdfDocumentProcessor As New PdfDocumentProcessor()
' Load a document
pdfDocumentProcessor.LoadDocument("Document.pdf")
Dim contentRegions As New PdfClearContentRegions()
' Find the target phrase in the document
Dim removeText As String = "Ounce"
Dim searchParameters As New PdfTextSearchParameters() With {.WholeWords = True}
Dim searchResults As PdfTextSearchResults = pdfDocumentProcessor.FindText(removeText, searchParameters)
Do While searchResults.Status = PdfTextSearchStatus.Found AndAlso searchResults.PageNumber = 1
' Add text rectangles to the region collection:
contentRegions.Add(searchResults.Rectangles)
searchResults = pdfDocumentProcessor.FindText(removeText, searchParameters)
Loop
' Get the first page properties
Dim pageFacade As PdfPageFacade = pdfDocumentProcessor.DocumentFacade.Pages(0)
' Specify what content type to keep in target areas
Dim options As New PdfClearContentOptions() With
{.ClearAnnotations = False, .ClearGraphics = False, .ClearImages = False}
' Remove found entries
pageFacade.ClearContent(contentRegions, options)
' Save the result
pdfDocumentProcessor.SaveDocument("Document_cleared.pdf")
End Using
See Also