
Annotations add clarifications, explanations, details, or comments to documents. In PDF files they are widely used, and many developers need to move these annotations to or from XFDF format. With Aspose.PDF for .NET, you can programmatically import and export PDF annotations using C# or VB.NET. This guide covers everything you need to get started.
- Annotations Importer or Exporter API – Installation
- Import Annotations from XFDF to PDF using C# or VB.NET
- Export Annotations from PDF to XFDF using C# or VB.NET
Annotations Importer or Exporter API – Installation
The Aspose.PDF for .NET library provides the PdfAnnotationEditor class, which contains methods for importing and exporting annotations between PDF and XFDF files. To start using the API, install the latest package via NuGet or download it from the official releases page.
PM> Install-Package Aspose.Pdf
The NuGet package supports .NET Framework 4.0+ and .NET Core/5+. After installation, add a reference to Aspose.Pdf in your project and you’re ready to work with PDF annotations.
Import Annotations from XFDF to PDF using C# or VB.NET
Importing XFDF annotations into a PDF is straightforward. The PdfAnnotationEditor class reads an XFDF file, maps the annotation types, and inserts them into the target PDF. Follow these steps:
- Create an instance of
PdfAnnotationEditor. - Load the source PDF document.
- Load the XFDF file that contains the annotations.
- Define which
AnnotationTypevalues you want to import (e.g., Highlight, Text, Ink). - Call
ImportAnnotationsXfdfto merge the annotations. - Save the updated PDF.
Below is a concise code example that demonstrates the import process for both C# and VB.NET.
Export Annotations from PDF to XFDF File using C# or VB.NET
Exporting annotations to XFDF lets you share, archive, or process specific comments separately from the original PDF. Use the PdfAnnotationEditor class to select annotation types and generate an XFDF file.
- Instantiate
PdfAnnotationEditor. - Open the PDF that contains the annotations.
- Create a new XFDF file path for the export.
- Choose the
AnnotationTypeyou wish to export (e.g., Highlight, StickyNote). - Execute
ExportAnnotationsXfdfto write the selected annotations to the XFDF file.
The following snippet shows how to export annotations using C# or VB.NET.
Conclusion
This article demonstrated how to import XFDF annotations into a PDF and export PDF annotations to XFDF using C# or VB.NET with Aspose.PDF for .NET. These capabilities are essential for workflows that require annotation sharing, review cycles, or selective content extraction. If you have specific scenarios or need assistance, join the discussion on our Free Support Forum. For deeper technical details, explore the API Documentation and API References.