We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

How to Import Annotation from XML in C#?

Hi Team,

I do exported annotation using below code which is working properly. How to import the very GDocs_annotations.xml before the document load.

           using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(path))
            {
                List<AnnotationBase> annotations = annotator.Get();
                XmlSerializer formatter = new XmlSerializer(typeof(List<AnnotationBase>));
                using (FileStream fs = new FileStream(@"E:\TEMP\GDocs_annotations.xml", FileMode.Create))
                {
                    fs.SetLength(0);
                    formatter.Serialize(fs, annotations);
                }
            }

Hello @mohamedriyas

For import try to use this code

public static T DeserializeAnnotations<T>(string filePath)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(T));
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                return (T)formatter.Deserialize(fs);
            }
        }
static void Main(string[] args)
        {
            using (Annotator annotator = new Annotator(filePath_PDF))
            {
                annotator.Add(DeserializeAnnotations<List<AnnotationBase>>(filePath_XML));
                annotator.Save("result.pdf", new SaveOptions());
            }
}