public AnnotatedDocumentEntity LoadDocument(AnnotationPostedDataEntity loadDocumentRequest, bool loadAllPages) { string password = loadDocumentRequest.password; AnnotatedDocumentEntity description = new AnnotatedDocumentEntity(); string documentGuid = loadDocumentRequest.guid; using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(documentGuid, GetLoadOptions(password))) { IDocumentInfo info = annotator.Document.GetDocumentInfo(); AnnotationBase[] annotations = annotator.Get().ToArray(); description.guid = loadDocumentRequest.guid; string documentType = getDocumentType(info); description.supportedAnnotations = new SupportedAnnotations().GetSupportedAnnotations(documentType); List <string> pagesContent = new List <string>(); if (loadAllPages) { pagesContent = GetAllPagesContent(annotator, info); } for (int i = 0; i < info.PagesInfo.Count; i++) { PageDataDescriptionEntity page = new PageDataDescriptionEntity { number = i + 1, height = info.PagesInfo[i].Height, width = info.PagesInfo[i].Width, }; if (annotations != null && annotations.Length > 0) { page.SetAnnotations(AnnotationMapper.MapForPage(annotations, i + 1, info.PagesInfo[i], documentType)); } if (pagesContent.Count > 0) { page.SetData(pagesContent[i]); } description.pages.Add(page); } } description.guid = documentGuid; // return document description return(description); }
public HttpResponseMessage LoadDocumentPage(AnnotationPostedDataEntity loadDocumentPageRequest) { string password = ""; try { // get/set parameters string documentGuid = loadDocumentPageRequest.guid; int pageNumber = loadDocumentPageRequest.page; password = loadDocumentPageRequest.password; PageDataDescriptionEntity loadedPage = new PageDataDescriptionEntity(); // get page image byte[] bytes; using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(documentGuid, GetLoadOptions(password))) { using (var memoryStream = RenderPageToMemoryStream(annotator, pageNumber)) { bytes = memoryStream.ToArray(); } IDocumentInfo info = annotator.Document.GetDocumentInfo(); AnnotationBase[] annotations = annotator.Get().ToArray(); string documentType = getDocumentType(info); if (annotations != null && annotations.Length > 0) { loadedPage.SetAnnotations(AnnotationMapper.MapForPage(annotations, pageNumber, info.PagesInfo[pageNumber - 1], documentType)); } string encodedImage = Convert.ToBase64String(bytes); loadedPage.SetData(encodedImage); loadedPage.height = info.PagesInfo[pageNumber - 1].Height; loadedPage.width = info.PagesInfo[pageNumber - 1].Width; loadedPage.number = pageNumber; } // return loaded page object return(Request.CreateResponse(HttpStatusCode.OK, loadedPage)); } catch (Exception ex) { // set exception message return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, password))); } }