Skip to main content
All docs
V25.1
  • PdfPageFacade Class

    Exposes members used to perform various operations on a PDF page without access to its inner structure.

    Namespace: DevExpress.Pdf

    Assembly: DevExpress.Pdf.v25.1.Core.dll

    NuGet Package: DevExpress.Pdf.Core

    Declaration

    public class PdfPageFacade

    Remarks

    The Pages property returns a list of PdfPageFacade objects used to organize PDF pages without access to their inner structure.

    The PdfPageFacade class allows you to perform the following actions:

    • Create, access, and flatten annotations
    • Create destinations
    • Clear page content

    Organize Annotations

    Refer to the following article for more information about annotations:

    Read Tutorial: Annotations in PDF Documents

    Add Annotations

    The Annotations property retrieves all page annotation properties.

    The table below lists available annotation types and API used to create these annotations:

    Annotation Class Method
    Link PdfLinkAnnotationFacade PdfPageFacade.AddLinkAnnotation
    Text Markup PdfTextMarkupAnnotationFacade PdfPageFacade.AddTextMarkupAnnotation
    Sticky Note PdfTextAnnotationFacade PdfPageFacade.AddTextAnnotation
    Caret PdfCaretAnnotationFacade PdfPageFacade.AddCaretAnnotation
    Rubber Stamp PdfRubberStampAnnotationFacade PdfPageFacade.AddRubberStampAnnotation
    Circle PdfCircleAnnotationFacade PdfPageFacade.AddCircleAnnotation
    Square PdfSquareAnnotationFacade PdfPageFacade.AddSquareAnnotation
    File Attachment PdfFileAttachmentAnnotationFacade PdfPageFacade.AddFileAttachmentAnnotation
    Free Text PdfFreeTextAnnotationFacade PdfPageFacade.AddFreeTextAnnotation
    Ink PdfInkAnnotationFacade PdfPageFacade.AddInkAnnotation
    Line PdfLineAnnotationFacade PdfPageFacade.AddLineAnnotation
    Polyline PdfPolyLineAnnotationFacade PdfPageFacade.AddPolyLineAnnotation
    Polygon PdfPolygonAnnotationFacade PdfPageFacade.AddPolygonAnnotation

    The code sample below creates a rubber stamp, file attachment, free text, and a circle annotation:

    markup annotations

    using DevExpress.Pdf;
    using System;
    using System.IO;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("..\\..\\Document.pdf");
    
        // Access the first page properties
        PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
        // Define a rubber stamp rectangle
        PdfRectangle rubberStampRectangle = new PdfRectangle(663, 526, 763, 576);
    
        // Create a "Draft" rubber stamp annotation
        PdfRubberStampAnnotationFacade rubberStamp =
            pageFacade.AddRubberStampAnnotation(rubberStampRectangle,
            PdfRubberStampAnnotationIconName.Draft);
        rubberStamp.Author = "Jesse Faden";
        rubberStamp.Contents = "Made in PDF Document API";
    
        // Define a file attachment area
        PdfPoint attachmentPoint = new PdfPoint(52, 550);
    
        // Specify attachment data
        PdfFileAttachment attachment = new PdfFileAttachment()
        {
            CreationDate = DateTime.Now,
            Description = "This is my attached file",
            FileName = "MyAttach.txt",
            Data = File.ReadAllBytes("..\\..\\FileToAttach.txt")
        };
    
        // Create a file attachment annotation
        PdfFileAttachmentAnnotationFacade pdfFileAttachment =
            pageFacade.AddFileAttachmentAnnotation(attachmentPoint, attachment,
            PdfFileAttachmentAnnotationIconName.PaperClip);
        pdfFileAttachment.Author = "Nancy Skywalker";
        pdfFileAttachment.Contents = "Additional Content";
    
        // Specify a free text annotation area
        PdfRectangle freeTextRectangle = new PdfRectangle(14, 321, 145, 340);
    
        // Create a free text annotation in this area
        PdfFreeTextAnnotationFacade freeTextAnnotation =
           pageFacade.AddFreeTextAnnotation(freeTextRectangle, "Free Text Annotation");
        freeTextAnnotation.Author = "Rayn Anita W";
    
        // Add a callout line
        freeTextAnnotation.SetCallout(PdfAnnotationLineEndingStyle.OpenArrow, new PdfPoint(152,351));
    
        // Find the target phrase in the document
        string circleText = "dogfooded";
        PdfTextSearchResults searchResults = processor.FindText(circleText);
    
        if (searchResults.Status == PdfTextSearchStatus.Found)
        {
            // Define an area around the phrase to add an annotation
            PdfRectangle circleRectangle = searchResults.Rectangles[0].BoundingRectangle;
    
            // Create a circle annotation in this area
            PdfCircleAnnotationFacade circleAnnotation = pageFacade.AddCircleAnnotation(circleRectangle);
            circleAnnotation.Author = "Cardle Anita W";
            circleAnnotation.Contents = "It's better to say 'used' in this case";
        }
    
        // Save the result
        processor.SaveDocument("..\\..\\Result.pdf");
    }
    

    Access Annotations

    The Annotations property returns all page annotation properties. You can filter annotation properties, cast them to the corresponding class, and use class properties to modify annotation parameters.

    Flatten Annotations

    Call the FlattenAnnotations method to flatten page annotations.

    The code sample below flattens all annotations that are located on the lower half of the first page:

    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
      // Load a document
      processor.LoadDocument("..\\..\\Document.pdf");
      PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
      // Flatten annotations located
      // on the lower half of the first page
      double halfPage = processor.Document.Pages[0].CropBox.Top / 2;
      pageFacade.FlattenAnnotations(x => x.Rectangle.Top < halfPage);
    
      // Save the result
      processor.SaveDocument("..\\..\\Result.pdf");
    }
    

    You can also flatten a specific annotation. Use the Annotations property to retrieve a list of annotation objects and call the Flatten() method.

    Clear Page Content

    Call the ClearContent method to remove content in one or multiple page areas. You can specify what content type to keep in the areas that are to be cleared. To do that, pass the PdfClearContentOptions class object as the method parameter.

    Run Demo: PDF Clear Page Content

    The code sample below removes only text in the upper half of the first page:

    result

    using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
    {
        // Load a document
        pdfDocumentProcessor.LoadDocument("Document.pdf");
    
        // Access the first page properties
        PdfPageFacade pageFacade = pdfDocumentProcessor.DocumentFacade.Pages[0];
    
        // Define an area to clear
        PdfRectangle cropBox = pdfDocumentProcessor.Document.Pages[0].CropBox;
        double halfPage = cropBox.Top / 2;
        PdfRectangle pageRectangle = new PdfRectangle(cropBox.Left, halfPage, cropBox.Right + halfPage, cropBox.Top);
    
        // Set what content type to keep
        PdfClearContentOptions options = new PdfClearContentOptions()
        {
          ClearAnnotations = false,
          ClearGraphics = false, 
          ClearImages = false
        };
    
        // Clear the page area
        pageFacade.ClearContent(pageRectangle, options);
    
        pdfDocumentProcessor.SaveDocument("Document_cleared.pdf");
    }
    

    Inheritance

    Object
    PdfPageFacade
    See Also