protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // Register and initialize once only, all other methods will use and share same objects/configs.

                // initializing AnnotationImageHandler object.
                annotator = UnityConfig.GetConfiguredContainer().Resolve <AnnotationImageHandler>();

                // initializing EmbeddedResourceManager object.
                _resourceManager = new EmbeddedResourceManager();

                //AnnotationHub.userGUID = "52ced024-26e0-4b59-a510-ca8f5368e315";
                // initializing AnnotationService object.
                _annotationSvc = UnityConfig.GetConfiguredContainer().Resolve <IAnnotationService>();

                //Here you should apply proper GroupDocs.Annotation license (in case you want to
                //use this sample without trial limits)
                GroupDocs.Annotation.License lic = new GroupDocs.Annotation.License();
                lic.SetLicense("C:/Users/Ali Ahmad/Documents/GroupDocs.Total.lic");
            }
        }
        public static ViewDocumentResponse ViewDocument(string path)
        {
            string request = path;

            try
            {
                GroupDocs.Annotation.License lic = new GroupDocs.Annotation.License();
                lic.SetLicense("C:/Users/Ali Ahmad/Documents/GroupDocs.Total.lic");
            }
            catch (Exception ex)
            {
                throw;
            }


            string fileName             = Path.GetFileName(request);
            var    pathFinder           = new ApplicationPathFinder();
            string _appPath             = HttpContext.Current.Server.MapPath("~/_layouts/15/GroupDocs_Annotation_SharePoint_WebPart/");
            ViewDocumentResponse result = new ViewDocumentResponse
            {
                pageCss        = new string[] { },
                lic            = true,
                pdfDownloadUrl = _appPath + "App_Data/" + request,
                url            = _appPath + "App_Data/" + request,
                path           = request,
                name           = fileName
            };
            DocumentInfoContainer docInfo = null;

            try
            {
                docInfo = annotator.GetDocumentInfo(request);
            }
            catch (Exception ex)
            {
                throw;
            }

            result.documentDescription = new FileDataJsonSerializer(docInfo.Pages).Serialize(true);
            result.docType             = docInfo.DocumentType;
            result.fileType            = docInfo.FileType;

            List <PageImage> imagePages = annotator.GetPages(request);

            // Provide images urls
            List <string> urls = new List <string>();

            // If no cache - save images to temp folder
            string tempFolderPath = HttpContext.Current.Server.MapPath("~/_layouts/15/GroupDocs_Annotation_SharePoint_WebPart/Content/TempStorage");


            foreach (PageImage pageImage in imagePages)
            {
                string docFoldePath = Path.Combine(tempFolderPath, request);

                if (!Directory.Exists(docFoldePath))
                {
                    Directory.CreateDirectory(docFoldePath);
                }

                string pageImageName = string.Format("{0}\\{1}.png", docFoldePath, pageImage.PageNumber);

                using (Stream stream = pageImage.Stream)
                    using (FileStream fileStream = new FileStream(pageImageName, FileMode.Create))
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.CopyTo(fileStream);
                    }
                string baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "_layouts/15/GroupDocs_Annotation_SharePoint_WebPart/";
                urls.Add(string.Format("{0}Content/TempStorage/{1}/{2}.png", baseUrl, request, pageImage.PageNumber));
            }

            result.imageUrls = urls.ToArray();

            // invoke event
            new DocumentOpenSubscriber().HandleEvent(request, _annotationSvc);

            return(result);
        }