Add Square Annotations in PDF using C#

Add Square annotation to PDF document programmaticaly using Aspose.PDF for .NET Library

In order to annotate PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for C# platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Add Square Annotation via .NET


You need aspose.pdf.dll to try the code in your environment.

  • Load PDF in an instance of Document class
  • Create a new page or get a reference to an existing one
  • Create Square annotation
  • Call method Add for Square annotation from Page.Annotations collections
  • Save the file again

System Requirements


Aspose.PDF for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, .NET Core, and PHP, VBScript, C++ via COM Interop
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for .NET DLL referenced in your project.

Add Square Annotations from PDF - C#

Example

    // Load the PDF file
    Document document = new Document(System.IO.Path.Combine(_dataDir, "sample.pdf"));
    // Create Square Annotation
    var squareAnnotation = new SquareAnnotation(document.Pages[1], new Rectangle(67, 317, 261, 459))
    {
        Title = "John Smith",
        Color = Color.Blue,
        InteriorColor = Color.BlueViolet,
        Opacity = 0.25,
        Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 196, 1021, 338))
    };
    document.Save(System.IO.Path.Combine(_dataDir, "sample_square.pdf"));