public PointAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     pointAnnotation = new PointAnnotation
     {
         Box = GetBox()
     };
 }
 public TextRedactionAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     textRedactionAnnotation = new TextRedactionAnnotation
     {
         Points = GetPoints(annotationData, pageInfo)
     };
 }
 public ResourceRedactionAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     this.resourcesRedactionAnnotation = new ResourcesRedactionAnnotation
     {
         Box = GetBox()
     };
 }
 private static AnnotationDataEntity RoundCoordinates(AnnotationDataEntity annotationData)
 {
     annotationData.height = (float)Math.Round(annotationData.height, 0);
     annotationData.left   = (float)Math.Round(annotationData.left, 0);
     annotationData.top    = (float)Math.Round(annotationData.top, 0);
     annotationData.width  = (float)Math.Round(annotationData.width, 0);
     return(annotationData);
 }
 public TextStrikeoutAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     strikeoutAnnotation = new StrikeoutAnnotation
     {
         Points = GetPoints(annotationData, pageInfo)
     };
 }
Example #6
0
 public DistanceAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     distanceAnnotation = new DistanceAnnotation
     {
         Box = GetBox()
     };
 }
Example #7
0
 public TextUnderlineAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     underlineAnnotation = new UnderlineAnnotation
     {
         Points = GetPoints(annotationData, pageInfo)
     };
 }
 public AreaAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     areaAnnotation = new AreaAnnotation
     {
         Box = GetBox()
     };
 }
Example #9
0
 public ArrowAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     this.arrowAnnotation = new ArrowAnnotation
     {
         Box = GetBox()
     };
 }
 public TextHighlightAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     highlightAnnotation = new HighlightAnnotation
     {
         Points = GetPoints(annotationData, pageInfo)
     };
 }
 public TextReplacementAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     replacementAnnotation = new ReplacementAnnotation
     {
         Points        = GetPoints(annotationData, pageInfo),
         TextToReplace = annotationData.text
     };
 }
 protected static List <Point> GetPointsForImages(AnnotationDataEntity annotationData, PageInfo pageInfo)
 {
     return(new List <Point>
     {
         new Point(annotationData.left, annotationData.top + annotationData.height),
         new Point(annotationData.left + annotationData.width, annotationData.top + annotationData.height),
         new Point(annotationData.left, annotationData.top),
         new Point(annotationData.left + annotationData.width, annotationData.top)
     });
 }
Example #13
0
 /// <summary>
 /// Fill creator name field in annotation info
 /// </summary>
 /// <param name="polylineAnnotation">AnnotationBase</param>
 protected static void FillCreatorName(AnnotationBase polylineAnnotation, AnnotationDataEntity annotationData)
 {
     CommentsEntity[] comments = annotationData.comments;
     if (comments != null && comments.Length > 0 && comments[0] != null)
     {
         polylineAnnotation.User = new User
         {
             Name = comments[0].userName
         };
     }
 }
Example #14
0
 public PolylineAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     this.polylineAnnotation = new PolylineAnnotation
     {
         Box      = GetBox(),
         PenColor = 1201033,
         PenWidth = 2,
         SvgPath  = annotationData.svgPath
     };
 }
 public TextFieldAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     textFieldAnnotation = new TextFieldAnnotation {
         Box = GetBox(),
         FontFamily = !string.IsNullOrEmpty(annotationData.font) ? annotationData.font : "Arial",
         FontColor = annotationData.fontColor,
         FontSize = annotationData.fontSize == 0 ? 12 : annotationData.fontSize,
         Text = annotationData.text
     };
 }
        /// <summary>
        /// Create annotator instance depending on type of annotation
        /// </summary>
        /// <param name="annotationData">AnnotationDataEntity</param>
        /// <param name="pageInfo">PageInfo</param>
        /// <returns></returns>
        public static BaseAnnotator createAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
        {
            AnnotationDataEntity roundedAnnotationData = RoundCoordinates(annotationData);

            switch (roundedAnnotationData.type)
            {
            case "textHighlight":
                return(new TextHighlightAnnotator(roundedAnnotationData, pageInfo));

            case "area":
                return(new AreaAnnotator(roundedAnnotationData, pageInfo));

            case "point":
                return(new PointAnnotator(roundedAnnotationData, pageInfo));

            case "textStrikeout":
                return(new TexStrikeoutAnnotator(roundedAnnotationData, pageInfo));

            case "polyline":
                return(new PolylineAnnotator(roundedAnnotationData, pageInfo));

            case "textField":
                return(new TextFieldAnnotator(roundedAnnotationData, pageInfo));

            case "watermark":
                return(new WatermarkAnnotator(roundedAnnotationData, pageInfo));

            case "textReplacement":
                return(new TextReplacementAnnotator(roundedAnnotationData, pageInfo));

            case "arrow":
                return(new ArrowAnnotator(roundedAnnotationData, pageInfo));

            case "textRedaction":
                return(new TextRedactionAnnotator(roundedAnnotationData, pageInfo));

            case "resourcesRedaction":
                return(new ResourceRedactionAnnotator(roundedAnnotationData, pageInfo));

            case "textUnderline":
                return(new TextUnderlineAnnotator(roundedAnnotationData, pageInfo));

            case "distance":
                return(new DistanceAnnotator(roundedAnnotationData, pageInfo));

            default:
                throw new ArgumentNullException("Wrong annotation data without annotation type!");
            }
        }
        /// <summary>
        /// Create annotator instance depending on type of annotation
        /// </summary>
        /// <param name="annotationData">AnnotationDataEntity</param>
        /// <param name="pageData">PageData</param>
        /// <returns></returns>
        public static BaseAnnotator createAnnotator(AnnotationDataEntity annotationData, PageData pageData)
        {
            switch (annotationData.type)
            {
            case "text":
                return(new TextAnnotator(annotationData, pageData));

            case "area":
                return(new AreaAnnotator(annotationData, pageData));

            case "point":
                return(new PointAnnotator(annotationData, pageData));

            case "textStrikeout":
                return(new TexStrikeoutAnnotator(annotationData, pageData));

            case "polyline":
                return(new PolylineAnnotator(annotationData, pageData));

            case "textField":
                return(new TextFieldAnnotator(annotationData, pageData));

            case "watermark":
                return(new WatermarkAnnotator(annotationData, pageData));

            case "textReplacement":
                return(new TextReplacementAnnotator(annotationData, pageData));

            case "arrow":
                return(new ArrowAnnotator(annotationData, pageData));

            case "textRedaction":
                return(new TextRedactionAnnotator(annotationData, pageData));

            case "resourcesRedaction":
                return(new ResourceRedactionAnnotator(annotationData, pageData));

            case "textUnderline":
                return(new TexUnderlineAnnotator(annotationData, pageData));

            case "distance":
                return(new DistanceAnnotator(annotationData, pageData));

            default:
                throw new System.Exception("Wrong annotation data without annotation type!");
            }
        }
Example #18
0
 /// <summary>
 /// Map AnnotationInfo instances into AnnotationDataEntity
 /// </summary>
 /// <param name="annotations">AnnotationInfo[]</param>
 /// <param name="pageNumber">int</param>
 /// <returns></returns>
 public AnnotationDataEntity[] mapForPage(AnnotationInfo[] annotations, int pageNumber)
 {
     // initiate annotations data array
     AnnotationDataEntity[] pageAnnotations = new AnnotationDataEntity[annotations.Length];
     //  each annotation data - this functionality used since annotations data returned by the
     // GroupDocs.Annotation library are obfuscated
     for (int n = 0; n < annotations.Length; n++)
     {
         AnnotationInfo annotationInfo = annotations[n];
         if (pageNumber == annotationInfo.PageNumber + 1)
         {
             AnnotationDataEntity annotation = mapAnnotationDataEntity(annotationInfo);
             pageAnnotations[n] = annotation;
         }
     }
     return(pageAnnotations);
 }
        /// <summary>
        /// Map AnnotationInfo instances into AnnotationDataEntity
        /// </summary>
        /// <param name="annotations">AnnotationInfo[]</param>
        /// <param name="pageNumber">int</param>
        /// <returns></returns>
        public static AnnotationDataEntity[] MapForPage(AnnotationBase[] annotations, int pageNumber, PageInfo pageInfo, string documentType)
        {
            // initiate annotations data array
            IList <AnnotationDataEntity> pageAnnotations = new List <AnnotationDataEntity>();

            //  each annotation data - this functionality used since annotations data returned by the
            // GroupDocs.Annotation library are obfuscated
            for (int n = 0; n < annotations.Length; n++)
            {
                AnnotationBase annotationInfo = annotations[n];
                if (pageNumber == annotationInfo.PageNumber + 1)
                {
                    AnnotationDataEntity annotation = MapAnnotationDataEntity(annotationInfo, pageInfo, documentType);
                    pageAnnotations.Add(annotation);
                }
            }

            return(pageAnnotations.ToArray());
        }
Example #20
0
        /// <summary>
        /// Map AnnotationInfo instances into AnnotationDataEntity
        /// </summary>
        /// <param name="annotationInfo">AnnotationInfo</param>
        /// <returns>AnnotationDataEntity</returns>
        public AnnotationDataEntity mapAnnotationDataEntity(AnnotationInfo annotationInfo)
        {
            AnnotationDataEntity annotation = new AnnotationDataEntity();

            annotation.font = annotationInfo.FontFamily;
            double fontSize = Convert.ToDouble((annotationInfo.FontSize == null) ? 0 : annotationInfo.FontSize);

            annotation.fontSize   = (float)fontSize;
            annotation.height     = annotationInfo.Box.Height;
            annotation.left       = annotationInfo.Box.X;
            annotation.pageNumber = (int)annotationInfo.PageNumber + 1;
            annotation.svgPath    = (annotationInfo.SvgPath != null) ? annotationInfo.SvgPath.Replace("l", "L") : null;
            string text = (annotationInfo.Text == null) ? annotationInfo.FieldText : annotationInfo.Text;

            annotation.text  = text;
            annotation.top   = annotationInfo.Box.Y;
            annotation.type  = Char.ToLowerInvariant(Enum.GetName(typeof(AnnotationType), annotationInfo.Type)[0]) + Enum.GetName(typeof(AnnotationType), annotationInfo.Type).Substring(1);
            annotation.width = annotationInfo.Box.Width;
            //  each reply data
            AnnotationReplyInfo[] replies = annotationInfo.Replies;
            if (replies != null && replies.Length > 0)
            {
                CommentsEntity[] comments = new CommentsEntity[replies.Length];
                for (int m = 0; m < replies.Length; m++)
                {
                    CommentsEntity      comment = new CommentsEntity();
                    AnnotationReplyInfo reply   = replies[m];
                    comment.text     = reply.Message;
                    comment.time     = reply.RepliedOn.ToString("yyyy-MM-dd HH:mm:ss");
                    comment.userName = reply.UserName;
                    comments[m]      = comment;
                }
                annotation.comments = comments;
            }
            return(annotation);
        }
        /// <summary>
        /// Map AnnotationInfo instances into AnnotationDataEntity
        /// </summary>
        /// <param name="annotationInfo">AnnotationInfo</param>
        /// <returns>AnnotationDataEntity</returns>
        public static AnnotationDataEntity MapAnnotationDataEntity(AnnotationBase annotationInfo, PageInfo pageInfo, string documentType)
        {
            string annotationTypeName = Enum.GetName(typeof(AnnotationType), annotationInfo.Type);
            float  maxY = 0, minY = 0, maxX = 0, minX = 0;
            float  boxX = 0, boxY = 0, boxHeight = 0, boxWidth = 0;
            string svgPath = "";

            if (annotationInfo is IPoints)
            {
                List <Point> points = ((IPoints)annotationInfo).Points;
                maxY = points.Max(p => p.Y);
                minY = points.Min(p => p.Y);
                maxX = points.Max(p => p.X);
                minX = points.Min(p => p.X);
            }

            if (annotationInfo is IBox)
            {
                Rectangle box = ((IBox)annotationInfo).Box;
                boxX      = box.X;
                boxY      = box.Y;
                boxHeight = box.Height;
                boxWidth  = box.Width;

                StringBuilder builder = new StringBuilder().
                                        Append("M").Append(box.X.ToString(CultureInfo.InvariantCulture)).
                                        Append(",").Append(box.Y.ToString(CultureInfo.InvariantCulture)).
                                        Append("L").Append(box.Width.ToString(CultureInfo.InvariantCulture)).
                                        Append(",").Append(box.Height.ToString(CultureInfo.InvariantCulture));

                svgPath = builder.ToString();
            }

            AnnotationDataEntity annotation = new AnnotationDataEntity();

            annotation.font = annotationInfo is IFontFamily ? ((IFontFamily)annotationInfo).FontFamily : "";
            double fontSize = annotationInfo is IFontSize?Convert.ToDouble((((IFontSize)annotationInfo).FontSize == null)? 0 : ((IFontSize)annotationInfo).FontSize) : (annotationInfo is ITextToReplace ? 10 : 0);

            annotation.fontSize   = (float)fontSize;
            annotation.fontColor  = annotationInfo is IFontColor ? ((((IFontColor)annotationInfo).FontColor == null) ? 0 : (int)((IFontColor)annotationInfo).FontColor) : 0;
            annotation.height     = annotationInfo is IBox ? boxHeight : (annotationInfo is IPoints ? (maxY - minY) : 0);
            annotation.left       = annotationInfo is IBox ? boxX : (annotationInfo is IPoints ? minX : 0);
            annotation.pageNumber = (int)annotationInfo.PageNumber + 1;
            annotation.svgPath    = annotationInfo is ISvgPath ? (((ISvgPath)annotationInfo).SvgPath?.Replace("l", "L")) : svgPath;
            string text = annotationInfo is IText ? ((IText)annotationInfo).Text : (annotationInfo is ITextToReplace ? ((ITextToReplace)annotationInfo).TextToReplace : "");

            annotation.text = text;
            // TODO: remove comment after check all annotations types on main formats
            annotation.top   = annotationInfo is IBox ? boxY : (annotationInfo is IPoints ? (!documentType.Equals("image") ? pageInfo.Height - maxY : minY) : 0);
            annotation.type  = char.ToLowerInvariant(annotationTypeName[0]) + annotationTypeName.Substring(1);
            annotation.width = annotationInfo is IBox ? boxWidth : (annotationInfo is IPoints ? (maxX - minX) : 0);
            //  each reply data
            Reply[] replies = annotationInfo.Replies.ToArray();
            if (replies != null && replies.Length > 0)
            {
                CommentsEntity[] comments = new CommentsEntity[replies.Length];
                for (int m = 0; m < replies.Length; m++)
                {
                    CommentsEntity comment = new CommentsEntity();
                    Reply          reply   = replies[m];
                    comment.text     = reply.Comment;
                    comment.time     = reply.RepliedOn.ToString("yyyy-MM-dd HH:mm:ss");
                    comment.userName = reply.User.Name;
                    comments[m]      = comment;
                }
                annotation.comments = comments;
            }
            return(annotation);
        }
 public TextRedactionAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
 }
 public ResourceRedactionAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
 }
Example #24
0
 public AbstractTextAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
 }
Example #25
0
 public TextReplacementAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
 }
 public PolylineAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
 }
Example #27
0
        public HttpResponseMessage Annotate(AnnotationPostedDataEntity annotateDocumentRequest)
        {
            AnnotatedDocumentEntity annotatedDocument = new AnnotatedDocumentEntity();

            try
            {
                // get/set parameters
                string documentGuid = annotateDocumentRequest.guid;
                string password     = annotateDocumentRequest.password;
                string documentType = SupportedImageFormats.Contains(Path.GetExtension(annotateDocumentRequest.guid).ToLowerInvariant()) ? "image" : annotateDocumentRequest.documentType;
                string tempPath     = GetTempPath(documentGuid);

                AnnotationDataEntity[] annotationsData = annotateDocumentRequest.annotationsData;
                // initiate list of annotations to add
                List <AnnotationBase> annotations = new List <AnnotationBase>();

                using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(documentGuid, GetLoadOptions(password)))
                {
                    IDocumentInfo info = annotator.Document.GetDocumentInfo();

                    for (int i = 0; i < annotationsData.Length; i++)
                    {
                        AnnotationDataEntity annotationData = annotationsData[i];
                        PageInfo             pageInfo       = info.PagesInfo[annotationsData[i].pageNumber - 1];
                        // add annotation, if current annotation type isn't supported by the current document type it will be ignored
                        try
                        {
                            BaseAnnotator baseAnnotator = AnnotatorFactory.createAnnotator(annotationData, pageInfo);
                            if (baseAnnotator.IsSupported(documentType))
                            {
                                annotations.Add(baseAnnotator.GetAnnotationBase(documentType));
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new AnnotatorException(ex.Message, ex);
                        }
                    }
                }

                // Add annotation to the document
                RemoveAnnotations(documentGuid, password);
                // check if annotations array contains at least one annotation to add
                if (annotations.Count != 0)
                {
                    using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(documentGuid, GetLoadOptions(password)))
                    {
                        foreach (var annotation in annotations)
                        {
                            annotator.Add(annotation);
                        }

                        annotator.Save(tempPath);
                    }

                    if (File.Exists(documentGuid))
                    {
                        File.Delete(documentGuid);
                    }

                    File.Move(tempPath, documentGuid);
                }

                annotatedDocument      = new AnnotatedDocumentEntity();
                annotatedDocument.guid = documentGuid;
                if (annotateDocumentRequest.print)
                {
                    annotatedDocument.pages = GetAnnotatedPagesForPrint(password, documentGuid);
                    File.Move(documentGuid, annotateDocumentRequest.guid);
                }
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex)));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, annotatedDocument));
        }
Example #28
0
 public TextFieldAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="annotationData"></param>
 /// <param name="pageInfo"></param>
 protected BaseAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
 {
     this.annotationData = annotationData;
     this.pageInfo       = pageInfo;
 }
Example #30
0
 public TextAnnotator(AnnotationDataEntity annotationData, PageData pageData)
     : base(annotationData, pageData)
 {
     SetFixTop(false);
 }