Add Text Annotations in PDF document via C#

Build your own .NET apps to manipulate comments & authors in document files using server-side APIs.

Work with annotations using the Aspose.PDF for .NET. Annotations are digital notes, comments, highlights, or other graphical elements that can be added to a PDF file to provide additional information or interact with the content. Add Text annotations to PDF using the Aspose.PDF for .NET. Adding annotations to a PDF file provides the usability and interactivity of the document, and improves presentations when using your document as a visual aid. Adding annotations to PDF can be used to create navigation tools, allowing users to access specific sections, websites, or external resources. Extracting annotations allows users to review comments, feedback, or notes made by others on the document, facilitating collaboration and discussion. The ability to get annotations from a document is necessary when working with large volumes of documents. The Aspose.PDF for .NET library can get annotations from PDF in a few steps. Annotations may contain private information. Removing Text annotations is necessary to ensure that such information is not unintentionally shared when sharing the PDF with others. Annotations may reveal data or information that needs to be protected for privacy reasons. Removing annotations helps safeguard data privacy. Annotations, especially excessive or outdated ones, can clutter a document and make it visually unappealing or harder to read. Removing Text annotations can enhance the overall document’s readability. 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 Text 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 Text annotation
  • Call method Add for Text 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, Delphi, C++ via COM Interop
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for .NET DLL referenced in your project.

Add Text Annotations from PDF - C#

Example

    // Load the PDF file
    Document document = new Document(System.IO.Path.Combine(_dataDir, "sample.pdf"));
    // This annotation is used to indicate the insertion of text
    var TextAnnotation1 = new TextAnnotation(document.Pages[1], new Rectangle(299.988, 713.664, 308.708, 720.769))
    {
        Title = "Aspose User",
        Subject = "Inserted text 1",
        Flags = AnnotationFlags.Print,
        Color = Color.Blue
    };
    document.Pages[1].Annotations.Add(TextAnnotation1);
    document.Save(System.IO.Path.Combine(_dataDir, "sample_Text.pdf"));