Skip to main content
All docs
V25.1
  • 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.v25.1.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