Back to Devexpress

PdfSquareAnnotationFacade Class

officefileapi-devexpress-dot-pdf-3954852f.md

latest8.3 KB
Original Source

PdfSquareAnnotationFacade Class

Exposes members used to organize square annotations without access to their inner structure.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfSquareAnnotationFacade :
    PdfShapeAnnotationFacade
vb
Public Class PdfSquareAnnotationFacade
    Inherits PdfShapeAnnotationFacade

The following members return PdfSquareAnnotationFacade objects:

Remarks

Create Square Annotations

The code sample below creates a square annotation.

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Define the area to add an annotation
    PdfRectangle rectangle = new PdfRectangle(663, 526, 763, 576);

    // Create a square annotation
    PdfSquareAnnotationFacade squareAnnotation = pageFacade.AddSquareAnnotation(rectangle);

    // Specify annotation parameters
    squareAnnotation.Author = "Nancy Davolio";
    squareAnnotation.Contents = "Made in PDF Document API";

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Define the area to add an annotation
  Dim rectangle As New PdfRectangle(663, 526, 763, 576)

  ' Create a square annotation
  Dim squareAnnotation As PdfSquareAnnotationFacade = pageFacade.AddSquareAnnotation(rectangle)

  ' Specify annotation parameters
  squareAnnotation.Author = "Nancy Davolio"
  squareAnnotation.Contents = "Made in PDF Document API"

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Edit Square Annotations

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

The code sample below retrieves all square annotations on the first page and changes their border and fill color.

csharp
using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all square annotations
    var squareAnnotations = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.Square);
    foreach (PdfSquareAnnotationFacade square in squareAnnotations)
    {
        // Change annotation parameters
        square.BorderWidth = 2.5;
        square.InteriorColor = new PdfRGBColor(1.00, 1.00, 0.00);
        square.Opacity = 0.7;
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Imports DevExpress.Pdf
Imports System.Linq

Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all square annotations
  Dim squareAnnotations = pageFacade.Annotations.Where(Function(annotation) annotation.Type = PdfAnnotationType.Square)
  For Each square As PdfSquareAnnotationFacade In squareAnnotations
    ' Change annotation parameters
    square.BorderWidth = 2.5
    square.InteriorColor = New PdfRGBColor(1.00, 1.00, 0.00)
    square.Opacity = 0.7
  Next square
  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Flatten Square Annotations

Call one of the following methods to flatten an annotation:

MethodDescription
PdfDocumentFacade.FlattenAnnotationsFlattens document annotations.
PdfPageFacade.FlattenAnnotationsFlattens annotations of a specific page.
PdfAnnotationFacade.Flatten()Flattens a specific annotation.

The code sample below flattens all square annotations on the first page.

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Flatten all square annotations
    pageFacade.FlattenAnnotations(PdfAnnotationType.Square);

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Flatten all square annotations
  pageFacade.FlattenAnnotations(PdfAnnotationType.Square)

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Remove Square Annotations

Call the PdfAnnotationFacade.Remove() method to remove a specific annotation.

The code sample below removes all square annotations from the first page.

csharp
using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all square annotations
    var squareAnnotations = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.Square).ToList();
    foreach (PdfSquareAnnotationFacade square in squareAnnotations)
    {
        // Remove each annotation
        square.Remove();
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Imports DevExpress.Pdf
Imports System.Linq

Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all square annotations
  Dim squareAnnotations = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.Square).ToList()
  For Each square As PdfSquareAnnotationFacade In squareAnnotations
    ' Remove each annotation
    square.Remove()
  Next square
  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfShapeAnnotationFacade PdfSquareAnnotationFacade

See Also

PdfSquareAnnotationFacade Members

DevExpress.Pdf Namespace