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, PdfClearContentOptions) Method

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.v24.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

#Declaration

public void ClearContent(
    PdfClearContentRegions regions,
    PdfClearContentOptions options
)

#Parameters

Name Type Description
regions PdfClearContentRegions

Page regions to clear.

options PdfClearContentOptions

Options that specify what content type to keep in target regions.

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

    // 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");
}
See Also