Exemple #1
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            MarkupAnnotationBase.CopyTo(Dictionary, res);

            IPDFObject name = Dictionary["Name"];

            if (name != null)
            {
                res.AddItem("Name", name.Clone());
            }

            RubberStampAnnotation annot = new RubberStampAnnotation(res, owner);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);

            return(annot);
        }
        private void AddAnnotation(object sender, RoutedEventArgs e)
        {
            // add annotation based on button's tag value.
            Button button     = (Button)sender;
            string actionName = button.Tag as string;

            if (this.document != null && this.document.NativePage != null && this.document.Page != null)
            {
                if (actionName == "star")
                {
                    Annotation starAnnotation = new RubberStampAnnotation(new Boundary(10, 400, 50, 440),
                                                                          AnnotationFlags.Default);
                    FixedContent fixedContent = new FixedContent("ap01", new Boundary(0, 0, 40, 40));
                    fixedContent.Content.AppendImage("star", 0, 0, 40, 40);
                    starAnnotation.Appearance.Normal = fixedContent;
                    this.document.NativePage.Annotations.Add(starAnnotation);

                    this.document.PageViewModel.Annotations.Add(new StarAnnotationViewModel(starAnnotation,
                                                                                            this.document.Page));
                }
                else if (actionName == "smile")
                {
                    Annotation starAnnotation = new RubberStampAnnotation(new Boundary(60, 400, 100, 440),
                                                                          AnnotationFlags.Default);
                    FixedContent fixedContent = new FixedContent("ap01", new Boundary(0, 0, 40, 40));
                    fixedContent.Content.AppendImage("smile", 0, 0, 40, 40);
                    starAnnotation.Appearance.Normal = fixedContent;
                    this.document.NativePage.Annotations.Add(starAnnotation);

                    this.document.PageViewModel.Annotations.Add(new SmileAnnotationViewModel(starAnnotation,
                                                                                             this.document.Page));
                }
                else if (actionName == "text")
                {
                    FreeTextAnnotation textAnnotation = new FreeTextAnnotation(new Boundary(60, 400, 260, 500));

                    string sampleText = "sample text";

                    textAnnotation.Appearance.Normal = AnnotationsHelper.CreateNormalAppearance(sampleText, 200, 100);

                    // set properties affecting default appearance to be used as fallback
                    textAnnotation.FontSize     = 12;
                    textAnnotation.BorderEffect = new AnnotationBorderEffect(AnnotationBorderEffectStyle.NoEffect, 0);
                    textAnnotation.Contents     = sampleText;
                    // text and border color
                    textAnnotation.TextColor = RgbColors.White.Components;
                    // set  background here if needed
                    textAnnotation.Color = RgbColors.Green.Components;

                    this.document.NativePage.Annotations.Add(textAnnotation);

                    this.document.PageViewModel.Annotations.Add(new TextAnnotationViewModel(textAnnotation,
                                                                                            this.document.Page));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AnnotationDefaults"/> class.
        /// </summary>
        public AnnotationDefaults()
        {
            _table = new Hashtable
            {
                { AnnotationType.Ellipse, new EllipseAnnotation(new AnnotationBrush(Color.Red), new AnnotationPen(Color.Red)) },
                { AnnotationType.EmbeddedImage, new EmbeddedImageAnnotation() },
                { AnnotationType.Freehand, new FreehandAnnotation(new AnnotationPen(Color.Blue, 4)) },
                { AnnotationType.Lines, new LinesAnnotation() },
                { AnnotationType.Polygon, new PolygonAnnotation(new AnnotationPen(Color.Black), new AnnotationBrush(Color.Green)) },
                { AnnotationType.Rectangle, new RectangleAnnotation(new AnnotationBrush(Color.Orange), new AnnotationPen(Color.Silver)) },
                { AnnotationType.ReferencedImage, new ReferencedImageAnnotation() },
                { AnnotationType.Text, new TextAnnotation(string.Empty, new AnnotationFont("Arial", 12), new AnnotationBrush(Color.Black), new AnnotationBrush(Color.Gainsboro), new AnnotationPen(Color.Black)) },
                { AnnotationType.Redaction, new RectangleAnnotation(new AnnotationBrush(Color.Black), null) }
            };

            // Callout
            var leader = new AnnotationPen(Color.Black, 2);

            leader.EndCap = new AnnotationLineCap(AnnotationLineCapStyle.Arrow, new SizeF(15, 15));
            _table.Add(AnnotationType.Callout, new CalloutAnnotation(string.Empty, new AnnotationFont("Times New Roman", 12), new AnnotationBrush(Color.Black), 4, new AnnotationBrush(Color.White), new AnnotationPen(Color.Black, 2), leader, 10));

            // Line
            var textOutline = new AnnotationPen(Color.Black);

            textOutline.EndCap = new AnnotationLineCap(AnnotationLineCapStyle.FilledArrow, new SizeF(15, 15));
            _table.Add(AnnotationType.Line, new LineAnnotation(textOutline));

            // Rubberstamp
            var stamp = new RubberStampAnnotation();

            stamp.Data.Size      = new SizeF(400, 110);
            stamp.Data.CanMirror = false;
            stamp.Text           = "DRAFT";
            _table.Add(AnnotationType.RubberStamp, stamp);

            // Sticky Note
            var sticky = new TextAnnotation(string.Empty, new AnnotationFont("Arial", 12), new AnnotationBrush(Color.Black), new AnnotationBrush(SystemColors.Info), new AnnotationPen(Color.Black, 1));

            sticky.Data.Size    = new SizeF(200, 120);
            sticky.Shadow       = new AnnotationBrush(Color.FromArgb(120, Color.Silver));
            sticky.ShadowOffset = new PointF(5, 5);
            _table.Add(AnnotationType.StickyNote, sticky);

            // Rectangle Highlighter
            var rc = new RectangleAnnotation(new AnnotationBrush(Color.Yellow), null);

            rc.Translucent = true;
            _table.Add(AnnotationType.RectangleHighlighter, rc);

            // Freehand Highlighter
            var fh = new FreehandAnnotation(new AnnotationPen(Color.Yellow, 20));

            fh.Translucent = true;
            fh.LineType    = FreehandLineType.Curves;
            _table.Add(AnnotationType.FreehandHighlighter, fh);
        }
Exemple #4
0
        public void TesRubberStampAnnotation()
        {
            Document document = new Document();

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

            annot.Contents = "PDF rubber stamp annotation";
            annot.Color    = new ColorRGB(80, 0, 150);

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

            //Process.Start("TestRubberStamp.pdf");
        }
Exemple #5
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);
                            }
                        }
                    }
                }
            }
        }