コード例 #1
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);

                float l = Left;
                float t = Top;
                float w = Width;
                float h = Height;
                float a = RotationAngle;

                Rectangle        = null;
                Rectangle.Left   = l;
                Rectangle.Top    = t;
                Rectangle.Width  = w;
                Rectangle.Height = h;
                Rectangle.Angle  = a;

                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            MarkupAnnotationBase.CopyTo(Dictionary, res);
            TextMarkupAnnotation.CopyTo(Dictionary, res, Page, page);

            UnderlineAnnotation annot = new UnderlineAnnotation(res, owner);

            annot.SetPage(page, true);
            return(annot);
        }
        public void PutUnderlineAnnotationTest()
        {
            UnderlineAnnotation annotation = new UnderlineAnnotation()
            {
                Name  = "Test Underline Annotation Updated",
                Rect  = new Rectangle(101, 101, 201, 201),
                Flags = new List <AnnotationFlags> {
                    AnnotationFlags.Hidden, AnnotationFlags.NoView
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                RichText            = "Rich Text Updated",
                Subject             = "Subj Updated",
                ZIndex     = 1,
                Title      = "Title Updated",
                QuadPoints = new List <Point>
                {
                    new Point(11, 11),
                    new Point(21, 11),
                    new Point(11, 21),
                    new Point(11, 11)
                },
                Modified = "02/02/2018 00:00:00.000 AM"
            };

            var    lineResponse = api.GetDocumentUnderlineAnnotations(Name, folder: FolderName);
            string annotationId = lineResponse.Annotations.List[0].Id;

            var response = api.PutUnderlineAnnotation(Name, annotationId, annotation, folder: FolderName);

            Console.WriteLine(response);
        }
コード例 #3
0
 public override AnnotationBase AnnotateImage()
 {
     underlineAnnotation           = InitAnnotationBase(underlineAnnotation) as UnderlineAnnotation;
     underlineAnnotation.FontColor = 1201033;
     underlineAnnotation.Points    = GetPointsForImages(annotationData, pageInfo);
     return(underlineAnnotation);
 }
        public void PutUnderlineAnnotationTest()
        {
            UnderlineAnnotation annotation = new UnderlineAnnotation(Rect: new Rectangle(101, 101, 201, 201))
            {
                Name  = "Test Underline Annotation Updated",
                Flags = new List <AnnotationFlags> {
                    AnnotationFlags.Hidden, AnnotationFlags.NoView
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                RichText            = "Rich Text Updated",
                Subject             = "Subj Updated",
                ZIndex     = 1,
                Title      = "Title Updated",
                QuadPoints = new List <Point>
                {
                    new Point(11, 11),
                    new Point(21, 11),
                    new Point(11, 21),
                    new Point(11, 11)
                },
                Modified = "02/02/2018 00:00:00.000 AM"
            };

            var    lineResponse = PdfApi.GetDocumentUnderlineAnnotations(Name, folder: TempFolder);
            string annotationId = lineResponse.Annotations.List[0].Id;

            var response = PdfApi.PutUnderlineAnnotation(Name, annotationId, annotation, folder: TempFolder);

            Assert.That(response.Code, Is.EqualTo(200));
        }
コード例 #5
0
 public TextUnderlineAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo)
     : base(annotationData, pageInfo)
 {
     underlineAnnotation = new UnderlineAnnotation
     {
         Points = GetPoints(annotationData, pageInfo)
     };
 }
コード例 #6
0
        public void TesUnderlineAnnotation()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            UnderlineAnnotation annot = new UnderlineAnnotation(100, 50, 75, 50);

            annot.Contents = "PDF underline annotation";
            annot.Color    = new ColorRGB(0, 50, 150);

            document.Pages[0].Annotations.Add(annot);
            document.Save(OutputFolder + @"\TestUnderlineAnnotation.pdf");
            document.Dispose();

            //Process.Start("TestUnderlineAnnotation.pdf");
        }
コード例 #7
0
        /**
         * Creates annotation, type of annotation is taken from given properties
         */
        public static Annotation CreateAnnotation(Document doc, Page page, int index, AnnotationProperties props)
        {
            Annotation ann      = null;
            int        addAfter = index - 1;

            switch (props.Subtype)
            {
            case "Line": ann = new LineAnnotation(page, props.BoundingRect, props.StartPoint, props.EndPoint, addAfter); break;

            case "Circle": ann = new CircleAnnotation(page, props.BoundingRect, addAfter); break;

            case "Square": ann = new SquareAnnotation(page, props.BoundingRect, addAfter); break;

            case "FreeText": ann = new FreeTextAnnotation(page, props.BoundingRect, "", addAfter); break;

            case "PolyLine": ann = new PolyLineAnnotation(page, props.BoundingRect, props.Vertices, addAfter); break;

            case "Polygon": ann = new PolygonAnnotation(page, props.BoundingRect, props.Vertices, addAfter); break;

            case "Link": ann = new LinkAnnotation(page, props.BoundingRect, addAfter); break;

            case "Ink": ann = new InkAnnotation(page, props.BoundingRect, addAfter); break;

            case "Underline": ann = new UnderlineAnnotation(page, addAfter, props.Quads); break;

            case "Highlight": ann = new HighlightAnnotation(page, addAfter, props.Quads); break;

            default: throw new Exception("Logic error");
            }
            AnnotationAppearance app = new AnnotationAppearance(doc, ann);

            app.CaptureAnnotation();
            app.Properties.SetFrom(props);
            app.Properties.Dirty = true;
            app.UpdateAppearance();
            app.ReleaseAnnotation();
            return(ann);
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("UnderlinesAndHighlights Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sInput  = "../../Resources/Sample_Input/sample.pdf";
                String sOutput = "../HighlightAndUnderlineAnnotations-out.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Document doc = new Document(sInput);

                Console.WriteLine("Opened a document " + sInput);

                Page docpage = doc.GetPage(0);

                //
                // Highlight occurrences of the word "cloudy" on the page.
                // Underline occurrences of the word "rain" on the page.
                //
                // For a more in-depth example of using the WordFinder, see the TextExtraction sample.
                //
                List <Quad>      cloudyQuads = new List <Quad>();
                List <Quad>      rainQuads   = new List <Quad>();
                WordFinderConfig wfc         = new WordFinderConfig();
                WordFinder       wf          = new WordFinder(doc, WordFinderVersion.Latest, wfc);
                IList <Word>     words       = wf.GetWordList(docpage.PageNumber);
                foreach (Word w in words)
                {
                    // Store the Quads of all "Cloudy" words in a list for later use in
                    // creating the annotation.
                    if (w.Text.ToLower().Equals("cloudy") ||
                        ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation &&
                         w.Text.ToLower().StartsWith("cloudy")))
                    {
                        cloudyQuads.AddRange(w.Quads);
                    }

                    // Store the Quads of all "Rain" words
                    if (w.Text.ToLower().Equals("rain") ||
                        ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation &&
                         w.Text.ToLower().StartsWith("rain")))
                    {
                        rainQuads.AddRange(w.Quads);
                    }
                }

                HighlightAnnotation highlights = new HighlightAnnotation(docpage, cloudyQuads);
                highlights.Color            = new Color(1.0, 0.75, 1.0);
                highlights.NormalAppearance = highlights.GenerateAppearance();

                UnderlineAnnotation underlines = new UnderlineAnnotation(docpage, rainQuads);
                underlines.Color            = new Color(0.0, 0.0, 0.0);
                underlines.NormalAppearance = underlines.GenerateAppearance();

                // Read back the text that was annotated.
                Console.WriteLine("Cloudy text: {0}", highlights.GetAnnotatedText(true));
                Console.WriteLine("Rainy text: {0}", underlines.GetAnnotatedText(false));

                doc.Save(SaveFlags.Full, sOutput);
            }
        }
コード例 #9
0
 public override AnnotationBase AnnotateSlides()
 {
     underlineAnnotation           = InitAnnotationBase(underlineAnnotation) as UnderlineAnnotation;
     underlineAnnotation.FontColor = 0;
     return(underlineAnnotation);
 }
コード例 #10
0
 public override AnnotationBase AnnotateWord()
 {
     underlineAnnotation           = InitAnnotationBase(underlineAnnotation) as UnderlineAnnotation;
     underlineAnnotation.FontColor = 1201033;
     return(underlineAnnotation);
 }
コード例 #11
0
        private void parseAnnotations()
        {
            for (int i = 0; i < _array.Count; ++i)
            {
                PDFDictionary annotDict = _array[i] as PDFDictionary;
                if (annotDict != null)
                {
                    if (annotDict["IRT"] == null)
                    {
                        PDFName subtype = annotDict["Subtype"] as PDFName;
                        if (subtype != null)
                        {
                            Annotation annot = null;
                            switch (subtype.GetValue())
                            {
                            case "Text":
                                annot = new TextAnnotation(annotDict, _owner);
                                break;

                            case "Link":
                                annot = new LinkAnnotation(annotDict, _owner);
                                break;

                            case "FreeText":
                                annot = new FreeTextAnnotation(annotDict, _owner);
                                break;

                            case "Line":
                                annot = new LineAnnotation(annotDict, _owner);
                                break;

                            case "Square":
                                annot = new SquareAnnotation(annotDict, _owner);
                                break;

                            case "Circle":
                                annot = new CircleAnnotation(annotDict, _owner);
                                break;

                            case "Polygon":
                                annot = new PolygonAnnotation(annotDict, _owner);
                                break;

                            case "PolyLine":
                                annot = new PolylineAnnotation(annotDict, _owner);
                                break;

                            case "Highlight":
                                annot = new HighlightAnnotation(annotDict, _owner);
                                break;

                            case "Underline":
                                annot = new UnderlineAnnotation(annotDict, _owner);
                                break;

                            case "Squiggly":
                                annot = new SquigglyAnnotation(annotDict, _owner);
                                break;

                            case "StrikeOut":
                                annot = new StrikeOutAnnotation(annotDict, _owner);
                                break;

                            case "Stamp":
                                annot = new RubberStampAnnotation(annotDict, _owner);
                                break;

                            case "Caret":
                                annot = new CaretAnnotation(annotDict, _owner);
                                break;

                            case "Ink":
                                annot = new InkAnnotation(annotDict, _owner);
                                break;

                            case "FileAttachment":
                                annot = new FileAttachmentAnnotation(annotDict, _owner);
                                break;

                            case "Sound":
                                annot = new SoundAnnotation(annotDict, _owner);
                                break;

                            case "Movie":
                                annot = new MovieAnnotation(annotDict, _owner);
                                break;

                            case "Screen":
                                annot = new ScreenAnnotation(annotDict, _owner);
                                break;

                            case "3D":
                                annot = new ThreeDAnnotation(annotDict, _owner);
                                break;

                            case "Widget":
                                PDFName ft = annotDict["FT"] as PDFName;
                                if (ft == null)
                                {
                                    PDFDictionary parent = annotDict["Parent"] as PDFDictionary;
                                    if (parent != null)
                                    {
                                        ft = parent["FT"] as PDFName;
                                    }
                                }

                                if (ft != null)
                                {
                                    switch (ft.GetValue())
                                    {
                                    case "Tx":
                                        annot = new EditBox(annotDict, _owner);
                                        break;

                                    case "Ch":
                                        uint flag = getFlag(annotDict);
                                        if ((flag >> 17) % 2 != 0)
                                        {
                                            annot = new ComboBox(annotDict, _owner);
                                        }
                                        else
                                        {
                                            annot = new ListBox(annotDict, _owner);
                                        }
                                        break;

                                    case "Btn":
                                        flag = getFlag(annotDict);
                                        if ((flag >> 16) % 2 != 0)
                                        {
                                            annot = new PushButton(annotDict, _owner);
                                        }
                                        else if ((flag >> 15) % 2 != 0)
                                        {
                                            annot = new RadioButton(annotDict, _owner);
                                        }
                                        else
                                        {
                                            annot = new CheckBox(annotDict, _owner);
                                        }
                                        break;
                                    }
                                }
                                break;
                            }

                            if (annot != null)
                            {
                                annot.SetPage(_page, false);
                                _annotations.Add(annot);
                            }
                        }
                    }
                }
            }
        }