Exemple #1
0
 /// <summary>
 ///     Annotation rectangle appearance
 /// </summary>
 /// <param name="AppearanceDixtionary">PDF X Object</param>
 public void Appearance
 (
     PdfXObject AppearanceDixtionary
 )
 {
     Dictionary.AddFormat("/AP", "<</N {0} 0 R>>", AppearanceDixtionary.ObjectNumber);
 }
Exemple #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))
            {
                var 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
                var File = (AnnotFileAttachment)AnnotAction;
                Dictionary.AddIndirectReference("/FS", File.EmbeddedFile);

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

            // add annotation object to page dictionary
            var 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
        }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw X Object
        /// </summary>
        /// <param name="XObject">X Object resource</param>
        /// <param name="OriginX">Origin X</param>
        /// <param name="OriginY">Origin Y</param>
        /// <param name="ScaleX">Horizontal scale factor</param>
        /// <param name="ScaleY">Vertical scale factor</param>
        /// <param name="Alpha">Rotation angle</param>
        ////////////////////////////////////////////////////////////////////
        public void DrawXObject(
			PdfXObject	XObject,
			Double		OriginX,
			Double		OriginY,
			Double		ScaleX,
			Double		ScaleY,
			Double		Alpha
			)
        {
            SaveGraphicsState();
            TranslateScaleRotate(OriginX, OriginY, ScaleX, ScaleY, Alpha);
            DrawXObject(XObject);
            RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw X Object
        /// </summary>
        /// <param name="XObject">X Object resource</param>
        /// <param name="OriginX">Origin X</param>
        /// <param name="OriginY">Origin Y</param>
        /// <remarks>
        /// X object Size is as per X object.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void DrawXObject(
			PdfXObject	XObject,
			Double		OriginX,
			Double		OriginY
			)
        {
            SaveGraphicsState();
            Translate(OriginX, OriginY);
            DrawXObject(XObject);
            RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw X Object
        /// </summary>
        /// <param name="XObject">X Object resource</param>
        /// <remarks>
        /// X object is displayed at current position. X object Size
        /// is as per X object.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void DrawXObject(
			PdfXObject	XObject
			)
        {
            // add image code to current list of resources
            AddToUsedResources(XObject);

            // draw object
            ContentsString.AppendFormat("{0} Do\n", XObject.ResourceCode);
            return;
        }
        /// <summary>
        /// Annotation rectangle appearance
        /// </summary>
        /// <param name="AppearanceDixtionary">PDF X Object</param>
        public void Appearance(
			PdfXObject	AppearanceDixtionary
			)
        {
            Dictionary.AddFormat("/AP", "<</N {0} 0 R>>", AppearanceDixtionary.ObjectNumber);
            return;
        }