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.ClearContent(PdfClearContentRegions) Method

Clears the document content located in the specified regions.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Core

#Declaration

public void ClearContent(
    PdfClearContentRegions regions
)

#Parameters

Name Type Description
regions PdfClearContentRegions

Page regions to clear.

#Remarks

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];

    // Remove found entries
    pageFacade.ClearContent(contentRegions);

    // Save the result
    pdfDocumentProcessor.SaveDocument("Document_cleared.pdf");
}
See Also