Save Memory by Exporting and Importing Annotations in WPF PDF Viewer
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (203)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (65)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (81)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (897)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (39)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (501)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (381)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (323)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Save Memory by Exporting and Importing Annotations in WPF PDF Viewer

Save Memory by Exporting and Importing Annotations in WPF PDF Viewer

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 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 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): 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: 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
Exporting and Importing Annotations in WPF PDF Viewer

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 method of the PDF Viewer.

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

// 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.

// 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 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 method of the WPF PDF Viewer. Refer to the following code example.

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 method of the PDF Viewer.

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

// 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.

// 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, pass the stream and the required format (FDF or XFDF) as parameters to the ImportAnnotations method of the WPF PDF Viewer. Refer to the following code example, where the stream object is created from a file.

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 of the WPF PDF Viewer.

References

For more information, refer to the following references:

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. 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. Otherwise, you can download a free, 30-day trial here.

If you have any questions on these features, please contact us through our support forum, support portal, or feedback portal. We are happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed