Skip to content

Instantly share code, notes, and snippets.

@farhan-raza
Created November 13, 2020 00:52
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 farhan-raza/9cb0e775efaf1a49854fb74112bd2d42 to your computer and use it in GitHub Desktop.
Save farhan-raza/9cb0e775efaf1a49854fb74112bd2d42 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