예제 #1
0
        private void ContructorHelper
        (
            PdfPage Page,
            PdfRectangle AnnotRect
        )
        {
            // save rectangle
            this.AnnotRect = AnnotRect;

            // area rectangle on the page
            Dictionary.AddRectangle("/Rect", AnnotRect);

            // annotation flags. value of 4 = Bit position 3 print
            Dictionary.Add("/F", "4");

            // add annotation object to page dictionary
            PdfKeyValue KeyValue = Page.Dictionary.GetValue("/Annots");

            if (KeyValue == null)
            {
                Page.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber);
            }

            else
            {
                Page.Dictionary.Add("/Annots", ((String)KeyValue.Value).Replace("]", String.Format(" {0} 0 R]", ObjectNumber)));
            }

            // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border
            Dictionary.Add("/BS", "<</W 0>>");

            // exit
            return;
        }
예제 #2
0
        /// <summary>
        /// PdfAnnotation constructor
        /// </summary>
        /// <param name="AnnotPage">Page object</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="AnnotAction">Annotation action</param>
        internal PdfAnnotation
        (
            PdfPage AnnotPage,
            PdfRectangle AnnotRect,
            AnnotAction AnnotAction
        ) : base(AnnotPage.Document)
        {
            // save arguments
            this.AnnotPage   = AnnotPage;
            this.AnnotRect   = AnnotRect;
            this.AnnotAction = AnnotAction;

            // annotation subtype
            Dictionary.Add("/Subtype", AnnotAction.Subtype);

            // area rectangle on the page
            Dictionary.AddRectangle("/Rect", AnnotRect);

            // annotation flags. value of 4 = Bit position 3 print
            Dictionary.Add("/F", "4");

            // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border
            Dictionary.Add("/BS", "<</W 0>>");

            // web link
            if (AnnotAction.GetType() == typeof(AnnotWebLink))
            {
                Dictionary.AddIndirectReference("/A", PdfWebLink.AddWebLink(Document, ((AnnotWebLink)AnnotAction).WebLinkStr));
            }

            // jump to destination
            else if (AnnotAction.GetType() == typeof(AnnotLinkAction))
            {
                if (Document.LinkAnnotArray == null)
                {
                    Document.LinkAnnotArray = new List <PdfAnnotation>();
                }
                Document.LinkAnnotArray.Add(this);
            }

            // display video or play sound
            else if (AnnotAction.GetType() == typeof(AnnotDisplayMedia))
            {
                PdfDisplayMedia DisplayMedia = ((AnnotDisplayMedia)AnnotAction).DisplayMedia;

                // action reference dictionary
                Dictionary.AddIndirectReference("/A", DisplayMedia);

                // add page reference
                Dictionary.AddIndirectReference("/P", AnnotPage);

                // add annotation reference
                DisplayMedia.Dictionary.AddIndirectReference("/AN", this);
            }

            // file attachment
            else if (AnnotAction.GetType() == typeof(AnnotFileAttachment))
            {
                // add file attachment reference
                AnnotFileAttachment File = (AnnotFileAttachment)AnnotAction;
                Dictionary.AddIndirectReference("/FS", File.EmbeddedFile);

                if (File.Icon != FileAttachIcon.NoIcon)
                {
                    // icon
                    Dictionary.AddName("/Name", File.Icon.ToString());
                }
                else
                {
                    // no icon
                    PdfXObject XObject = new PdfXObject(Document, AnnotRect.Right, AnnotRect.Top);
                    Dictionary.AddFormat("/AP", "<</N {0} 0 R>>", XObject.ObjectNumber);
                }
            }

            // sticky notes
            else if (AnnotAction.GetType() == typeof(AnnotStickyNote))
            {
                // short cut
                AnnotStickyNote StickyNote = (AnnotStickyNote)AnnotAction;

                // icon
                Dictionary.AddName("/Name", StickyNote.Icon.ToString());

                // action reference dictionary
                Dictionary.AddPdfString("/Contents", StickyNote.Note);
            }

            // add annotation object to page dictionary
            PdfKeyValue KeyValue = AnnotPage.Dictionary.GetValue("/Annots");

            if (KeyValue == null)
            {
                AnnotPage.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber);
            }

            else
            {
                AnnotPage.Dictionary.Add("/Annots", ((string)KeyValue.Value).Replace("]", string.Format(" {0} 0 R]", ObjectNumber)));
            }

            // exit
            return;
        }