Annotations are often used to add clarifications, explanations, details, or comments to some documents. In PDF files, annotations are frequently used and you might need to import or export them to XFDF format. You can easily import or export annotations programmatically using C# or VB.NET. Let us go through the following contents:
- 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
Aspose.PDF for .NET API exposes different classes, properties, and methods to work with PDF files. Likewise, you can import or export annotations from PDF documents to the XFDF file with PDFAnnotationEditor class. It exposes different methods that can be used to import or export annotations programmatically. You need to install the API by downloading it from New Releases, or via NuGet solution manager in Microsoft Visual Studio IDE. The following command can be used to install the API:
PM> Install-Package Aspose.Pdf
Import Annotations from XFDF to PDF using C# or VB.NET
You can import annotations into PDF file from existing XFDF file in your .NET based applications using C# or VB.NET programming languages. The API supports importing different types of annotations as listed under the AnnotationType Enumeration in API references. Let us follow the following steps to import annotations from XFDF to PDF using C# or VB.NET programming languages in your .NET framework based applications.
- Initialize PdfAnnotationEditor class object
- Load the input PDF document
- Load the XFDF file to import annotations
- Specify the annotation types that you want to import
- Import annotations from XFDF to PDF file
- Save the output PDF file
The code snippet below shows how to import annotations from XFDF file to PDF file using C# or VB.NET:
Export Annotations from PDF to XFDF File using C# or VB.NET
Exporting of annotations from PDF files can be helpful for making the file presentable or for keeping intact only a specific type of annotations. For example, when someone is reviewing a feasibility report or a thesis submission, let us assume, they may highlight some text, add comments or text. Later they want to keep only the text before sending the PDF back to the author. In such scenarios, exporting of annotations to XFDF can help because it lets you export specific annotations as per your requirements. The following steps show how to export annotations from PDF to XFDF format:
- Initialize PdfAnnotationEditor object
- Load input PDF file
- Create XFDF file to save exported annotations
- Specify annotation type to Export
- Export the annotations with the ExportAnnotationsXfdf method
The code snippet below shows how to export annotations from PDF file to XFDF file using C# or VB.NET:
Conclusion
In this article, we have explored how to import and export annotations from PDF to XFDF format. We have explored different examples and scenarios where importing or exporting the annotations can be helpful. Likewise, there are many use cases and scenarios where this feature is valuable. If you want to discuss any scenario then feel free to contact us at Free Support Forum. You can also explore the API by learning from API Documentation as well as API References. We look forward to hearing from you!