public GetAnnotationsResponse GetAnnotations(GetAnnotationsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            return(AnnotationMethods.GetAnnotations(request));
        }
        public static GetAnnotationsResponse GetAnnotations(GetAnnotationsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (string.IsNullOrEmpty(request.DocumentId))
            {
                throw new ArgumentException("documentId must not be null");
            }

            if (request.PageNumber < 0)
            {
                throw new ArgumentException("'pageNumber' must be a value greater than or equal to 0");
            }

            // If page number is 0, get all annotations

            // Now load the document
            var cache = ServiceHelper.Cache;

            using (var document = DocumentFactory.LoadFromCache(cache, request.DocumentId))
            {
                DocumentHelper.CheckLoadFromCache(document);

                var    annCodec    = new AnnCodecs();
                string annotations = null;
                if (request.PageNumber == 0)
                {
                    var containers = document.Annotations.GetAnnotations(request.CreateEmpty);
                    annotations = annCodec.SaveAllToString(containers, AnnFormat.Annotations);
                }
                else
                {
                    DocumentHelper.CheckPageNumber(document, request.PageNumber);

                    var documentPage = document.Pages[request.PageNumber - 1];

                    var container = documentPage.GetAnnotations(request.CreateEmpty);
                    if (container != null)
                    {
                        annotations = annCodec.SaveToString(container, AnnFormat.Annotations, request.PageNumber);
                    }
                }
                return(new GetAnnotationsResponse {
                    Annotations = annotations
                });
            }
        }