import export pdf xfdf annotations

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

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:

  1. Create an instance of PdfAnnotationEditor.
  2. Load the source PDF document.
  3. Load the XFDF file that contains the annotations.
  4. Define which AnnotationType values you want to import (e.g., Highlight, Text, Ink).
  5. Call ImportAnnotationsXfdf to merge the annotations.
  6. 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.

  1. Instantiate PdfAnnotationEditor.
  2. Open the PDF that contains the annotations.
  3. Create a new XFDF file path for the export.
  4. Choose the AnnotationType you wish to export (e.g., Highlight, StickyNote).
  5. Execute ExportAnnotationsXfdf to 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.

See Also