Skip to main content
All docs
V25.1
  • PdfPageFacade.ClearContent(PdfClearContentRegions) Method

    Clears the document content located in the specified regions.

    Namespace: DevExpress.Pdf

    Assembly: DevExpress.Pdf.v25.1.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