Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created January 19, 2021 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/f9cb92721e6cb98cbed3f2bc3bac72a5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/f9cb92721e6cb98cbed3f2bc3bac72a5 to your computer and use it in GitHub Desktop.
Import or Export Annotations from PDF and XFDF using C# VB.NET
// Create an object of PdfAnnotationEditor class
PdfAnnotationEditor editor = new PdfAnnotationEditor();
// Bind input PDF file
editor.BindPdf(dataDir + "inFile.pdf");
// Create a file stream for output XFDF file to export annotations
FileStream fileStream = new FileStream(dataDir + "exportannotations.xfdf", FileMode.Create, FileAccess.Write);
// Create an enumeration of all the annotation types which you want to export
Enum[] annoType = { AnnotationType.Text };
// Export annotations of specified type(s) to XFDF file
editor.ExportAnnotationsXfdf(fileStream, 1, 5, annoType);
// Create an object of PdfAnnotationEditor class
PdfAnnotationEditor editor = new PdfAnnotationEditor();
// Bind input PDF file
editor.BindPdf(dataDir + "inFile.pdf");
// Create a file stream for input XFDF file to import annotations
FileStream fileStream = new FileStream(dataDir + "exportannotations.xfdf", FileMode.Open, FileAccess.Read);
// Create an enumeration of all the annotation types which you want to import
Enum[] annType = { AnnotationType.Text };
// Import annotations of specified type(s) from XFDF file
editor.ImportAnnotationFromXfdf(fileStream, annType);
// Save output pdf file
editor.Save(dataDir + "ImportAnnotations_out.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment