How to Save Annotated Pages in PDF Using GroupDocs.Annotation for .NET
Introduction
Struggling to save specific annotated pages from your PDF documents? This comprehensive guide demonstrates how to efficiently achieve this using GroupDocs.Annotation for .NET. By leveraging annotation capabilities, streamline document management and enhance collaboration by focusing on relevant content.
In this tutorial, you’ll learn:
- Setting up your development environment with GroupDocs.Annotation
- Adding various types of annotations
- Saving only annotated pages effectively
Ready to start? Let’s ensure you have everything ready.
Prerequisites
Before beginning, make sure you have the following:
- .NET Framework (version 4.6 or later) or .NET Core/5+
- A code editor like Visual Studio
- Basic knowledge of C# and .NET project setup
Setting Up GroupDocs.Annotation for .NET
To start using GroupDocs.Annotation, install it via NuGet.
NuGet Package Manager Console
Install-Package GroupDocs.Annotation -Version 25.4.0
.NET CLI
dotnet add package GroupDocs.Annotation --version 25.4.0
License Acquisition
GroupDocs offers a free trial to explore their software fully. For extended use, purchase a license or request a temporary one:
- Free Trial: Explore features without limitations for an initial period.
- Temporary License: Use GroupDocs.Annotation in production temporarily.
- Purchase: Secure your long-term needs with a commercial license.
Once installed, initialize the library as follows:
using GroupDocs.Annotation;
// Basic setup to load and annotate documents
Annotator annotator = new Annotator("path/to/your/document.pdf");
Implementation Guide
Adding Annotations
Overview
Annotations help highlight important areas within your document. Let’s explore adding an AreaAnnotation
and an EllipseAnnotation
.
Step 1: Create Area Annotation
using GroupDocs.Annotation.Models;
using GroupDocs.Annotation.Models.AnnotationModels;
// Define the area annotation
AreaAnnotation area = new AreaAnnotation()
{
Box = new Rectangle(100, 100, 100, 100), // Position and size
BackgroundColor = 65535, // ARGB color value for highlight
PageNumber = 1 // Specific page number
};
The AreaAnnotation
highlights a rectangular area on the document. Customize its position (Box
) and background color.
Step 2: Create Ellipse Annotation
// Define the ellipse annotation
EllipseAnnotation ellipse = new EllipseAnnotation()
{
Box = new Rectangle(100, 100, 100, 100), // Position and size
BackgroundColor = 123456, // ARGB color value for highlight
PageNumber = 1 // Specific page number
};
The EllipseAnnotation
allows drawing an oval shape on the document. Adjust position and dimensions using the Box
property.
Step 3: Add Annotations
// Adding annotations to the Annotator instance
annotator.Add(new List<AnnotationBase>() { area, ellipse });
Using the Add
method, include multiple types of annotations. This step adds both the AreaAnnotation
and EllipseAnnotation
.
Saving Only Annotated Pages
Overview
To save only pages containing annotations, configure your save options accordingly.
Step 4: Save Annotated Pages
using GroupDocs.Annotation.Options;
// Set up save options to include only annotated pages
annotator.Save("path/to/output/document.pdf\