Save Memory by Exporting and Importing Annotations in WPF PDF Viewer
Tags: csharp, dotnet, wpf, pdf
Published: 2021-12-02 11:46:46

---
title: Save Memory by Exporting and Importing Annotations in WPF PDF Viewer
published: true
date: 2021-12-02 11:00:13 UTC
tags: csharp, dotnet, wpf, pdf
canonical_url: https://www.syncfusion.com/blogs/post/save-memory-by-exporting-and-importing-annotations-in-wpf-pdf-viewer.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65fzzz6ck6w1et2d7vhv.png
---

[PDF](https://en.wikipedia.org/wiki/PDF "Wikipedia link to PDF") files are primarily intended for viewing rather than editing. They were developed to present document content (text, images, and other elements) in the same manner, regardless of the operating system, device, or software application on which they are viewed. To add more information to a PDF document, annotations are used.

[Annotations](https://en.wikipedia.org/wiki/Annotation "Wikipedia link to Annotation") are additional details that include explanations, clarifications, review comments, and highlights (key points) on the original PDF file’s contents.

Let’s consider the case of an online PDF library, where the users access different PDF books and want to highlight the key points and save them. Usually, to save highlighted points in a PDF file, the entire file has to be saved along with the annotations. For large PDF files, maintaining multiple copies for each user would consume a lot of memory. The more effective way to handle this would be to export just the annotations as separate files for individual users and import them when the users load the PDF file. For a PDF document megabytes in size, the size of the exported annotations will be in kilobytes.

In this blog, we will look at how to export and import annotations in PDF documents using the WPF PDF Viewer.

## Syncfusion WPF PDF Viewer

Syncfusion’s [WPF PDF Viewer](https://www.syncfusion.com/wpf-controls/pdf-viewer "Link to WPF PDF Viewer") control lets you view, review, and print PDF files in WPF applications. The thumbnail, bookmark, hyperlink, and table of contents support provide easy navigation within and outside the PDF files. The form-filling support provides a platform to fill, flatten, save, and print PDF files with AcroForm.

You can review PDF files with abundant annotation tools. You can add, modify, and remove these annotations using the WPF PDF Viewer. Also, we can easily save, print, and export them.

## Annotation import and export formats

The WPF PDF Viewer supports exporting and importing the annotation data from a PDF in FDF and XFDF formats.

[**FDF (forms data format)**](https://en.wikipedia.org/wiki/FDF "Wikipedia link to FDF"): This format allows us to export forms data to stand-alone files. We can save and transmit the exported data electronically and then import it back into the corresponding PDF file.

[**XFDF**](https://en.wikipedia.org/?title=XFDF&redirect=no "Wikipedia link to XFDF"): This is an XML version of the forms data format (FDF). It is the simplified version of PDF for representing forms data and annotations. Its document structure is simpler than that of PDF. The file size is much smaller in terms of KBs because they contain just the form’s data and annotations, not all the PDF content.

Refer to the following GIF image.

![Exporting and Importing Annotations in WPF PDF Viewer](https://www.syncfusion.com/blogs/wp-content/uploads/2021/12/Exporting-and-Importing-Annotations-in-WPF-PDF-Viewer.gif)
<figcaption>Exporting and Importing Annotations in WPF PDF Viewer</figcaption>

## Export annotations from a PDF

Exporting annotations will only extract the annotation details from the PDF files, leaving all other PDF content and document structural information behind. The exported data is simple and you can save it either in a file or a stream. We can also easily transfer it between documents and applications (PDF readers) as the size of the exported annotations is much smaller than the entire PDF.

As described earlier, you can easily export annotations from a PDF loaded in the WPF PDF Viewer. To do so, pass the file name (name used to save the exported annotations) and the format details as parameters to the [ExportAnnotations](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_ExportAnnotations_System_String_Syncfusion_Pdf_Parsing_AnnotationDataFormat_ "Link to the ExportAnnotations property of WPF PDF Viewer") method of the PDF Viewer.

Refer to the following code example to export annotations from a PDF to an FDF file.

```csharp
// Export the annotation data to an FDF file in the 'D' folder named "Annotations.fdf".
pdfViewer.ExportAnnotations(@"D:\Annotations.fdf", AnnotationDataFormat.Fdf);
```

Refer to the following code example to export annotations from a PDF to an XFDF file.

```csharp
// Export the annotation data to an XFDF file in the 'D' folder named "Annotations.xfdf".
pdfViewer.ExportAnnotations(@"D:\Annotations.xfdf", AnnotationDataFormat.XFdf);
```

You can also export the annotations to a [Stream](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream?view=net-5.0 "Link to the Stream Class") instead of saving them to a file. To do so, pass the stream and the required format (FDF or XFDF) as parameters to the [ExportAnnotations](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_ExportAnnotations_System_IO_Stream_Syncfusion_Pdf_Parsing_AnnotationDataFormat_ "Link to the ExportAnnotations method of WPF PDF Viewer") method of the WPF PDF Viewer. Refer to the following code example.

```csharp
Stream stream = new MemoryStream();
// Export the annotations to a stream in XFDF format.
pdfViewer.ExportAnnotations(stream, AnnotationDataFormat.XFdf);
```

## Import annotations to a PDF

Similar to exporting, you can import annotations either from a file or a stream in the WPF PDF Viewer. On import, the file or stream containing annotation details will be quickly transformed to annotations and placed over the corresponding PDF pages. You can also easily import annotations from various PDF reader applications. That is, an annotation exported using Adobe Acrobat can be imported in Syncfusion WPF PDF Viewer and vice versa.

As described earlier, you can import annotations to a PDF from FDF and XFDF formats. To do so, pass the file name and the required format as parameters to the [ImportAnnotations](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_ImportAnnotations_System_String_Syncfusion_Pdf_Parsing_AnnotationDataFormat_ "Link to the ImportAnnotations method of WPF PDF Viewer") method of the PDF Viewer.

Refer to the following code example to import annotations to a PDF from an FDF file.

```csharp
// Import the annotations from an FDF file in the 'D' folder named "Annotations.fdf".
pdfViewer.ImportAnnotations(@"D:\Annotations.fdf", AnnotationDataFormat.Fdf);
```

Similarly, refer to the following code example to import annotations to a PDF from an XFDF file.

```csharp
// Import annotations from an XFDF file in the 'D' folder named "Annotations.xfdf".
pdfViewer.ImportAnnotations(@"D:\Annotations.xfdf", AnnotationDataFormat.XFdf);
```

To import the annotations from a [Stream](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream?view=net-5.0 "Link to the Stream Class"), pass the stream and the required format (FDF or XFDF) as parameters to the [ImportAnnotations](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_ImportAnnotations_System_IO_Stream_Syncfusion_Pdf_Parsing_AnnotationDataFormat_ "Link to the ImportAnnotations method of WPF PDF Viewer") method of the WPF PDF Viewer. Refer to the following code example, where the stream object is created from a file.

```csharp
Stream stream = new FileStream(@"D:\Annotations.xfdf", FileMode.Open);
// Imports annotations from a stream object.
pdfViewer.ImportAnnotations(stream, annotationDataFormat);
```

**Note:** To revert the import operation, perform an undo operation using the shortcut key **Ctrl + Z** or the [UndoCommand](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_UndoCommand "Link to the UndoCommand property of WPF PDF Viewer") of the WPF PDF Viewer.

## References

For more information, refer to the following references:

- [Demo project] [Export and Import Annotations in WPF PDF Viewer](https://github.com/SyncfusionExamples/WPF-PDFViewer-Examples/tree/master/Annotations/Import%20and%20Export "Link to Import and Export Annotation in WPF PDF Viewer GitHub demo")
- [Documentation] [Annotations supported by WPF PDF Viewer](https://help.syncfusion.com/wpf/pdf-viewer/working-with-annotations/annotations "Documentation link to Annotations in WPF PDF Viewer")
- [Documentation] [Export and import annotations in WPF PDF Viewer](https://help.syncfusion.com/wpf/pdf-viewer/working-with-annotations/export-and-import-annotations "Documentation link to Exporting and Importing Annotations in WPF PDF Viewer")

## Conclusion

Thank you for reading this blog. We have seen how to export and import annotations in PDF files using the Syncfusion [WPF PDF Viewer](https://www.syncfusion.com/wpf-controls/pdf-viewer "Link to WPF PDF Viewer"). With these features, we can save a lot of time and memory by saving only the annotations instead of saving and transferring an entire PDF file. Try using our PDF Viewer in your app and let us know what you think in the comment section below.

If you’re already a Syncfusion user, you can download the product set up on the [downloads page](https://www.syncfusion.com/account/downloads "Link to license and download page of Essential Studio"). Otherwise, you can download a free, 30-day trial [here](https://www.syncfusion.com/downloads/fileformats/verify "Link to the free evaluation of the Syncfusion Essential Studio").

If you have any questions on these features, please contact us through our [support forum](https://www.syncfusion.com/forums "Link to the Syncfusion support forum"), [support portal](https://support.syncfusion.com/ "Link to the Syncfusion Support Portal"), or [feedback portal](https://www.syncfusion.com/feedback/ "Link to Syncfusion Feedback Portal"). We are happy to assist you!

## Related blogs

- [Create, Edit, and Delete Arrows Shapes in PDF Files with Ease in WPF](https://dev.to/syncfusion/create-edit-and-delete-arrows-shapes-in-pdf-files-with-ease-in-wpf-3n2c "Link to Create, Edit, and Delete Arrows Shapes in PDF Files with Ease in WPF blog")
- [Rotate, Remove, and Rearrange PDF Pages Easily with WPF PDF Viewer](https://dev.to/syncfusion/rotate-remove-and-rearrange-pdf-pages-easily-with-wpf-pdf-viewer-38p1 "Link to Rotate, Remove, and Rearrange PDF Pages Easily with WPF PDF Viewer blog")
- [Add, Edit, and Delete Cloud Shapes in PDF Files with Ease in WPF](https://dev.to/karthickramasamy08/add-edit-and-delete-cloud-shapes-in-pdf-files-with-ease-in-wpf-4l52-temp-slug-4649139 "Link to Add, Edit, and Delete Cloud Shapes in PDF Files with Ease in WPF blog")
- [Printing PDF Files in WPF—A Complete Guide](https://dev.to/syncfusion/printing-pdf-files-in-wpf-a-complete-guide-gpo "Link to Printing PDF Files in WPF—A Complete Guide blog")