Exporting and Importing Annotations

8 Sep 20211 minute to read

PDF viewer allows the users to import and export information of annotations in PDF files. The annotation information can be exported and imported in the following data formats.

  • fdf
  • xfdf

The required data format can be chosen from the AnnotationDataFormat enumeration. In the following sections, the fdf data format is explained for brevity and similarly we can implement for xfdf.

Exporting annotations

The ExportAnnotations method exports the annotations added in the document to a file or stream in specified file format. The annotation data format should be given as an arguments.

//Export annotations to "fdf" data format to file 
pdfViewer.ExportAnnotations("Annotation.fdf ", AnnotationDataFormat.fdf);

//Export annotations to "fdf" data format to stream
Stream stream = new MemoryStream();
pdfViewer.ExportAnnotations(stream, AnnotationDataFormat.fdf);

Importing annotations

The ImportAnnotations method imports the annotations from the file or file stream of a specified type and fills the annotations into the loaded PDF document. The full path of file or file stream contains the annotation information. The annotation data format should be given as the arguments.

//Import annotations to "fdf " data format
pdfViewer.ImportAnnotations("Annotation.fdf ", AnnotationDataFormat.fdf);

//Export annotations to "fdf" data format to stream
pdfViewer.ImportAnnotations (stream, AnnotationDataFormat.fdf);