/// <summary>
        /// Set media window
        /// </summary>
        /// <param name="MediaWindow">Media window</param>
        /// <param name="Width">Floating window width</param>
        /// <param name="Height">Floating window height</param>
        /// <param name="Position">Floating window position</param>
        /// <param name="TitleBar">Floating window title bar</param>
        /// <param name="Resize">Floating window resize</param>
        /// <param name="Title">Floating window title</param>
        /// <remarks>
        /// <para>
        /// All optional arguments are applicable to floating window only.
        /// </para>
        /// </remarks>
        public void SetMediaWindow(
			MediaWindow			MediaWindow,
			Int32				Width = 0,
			Int32				Height = 0,
			WindowPosition		Position = WindowPosition.Center,
			WindowTitleBar		TitleBar = WindowTitleBar.TitleBarWithCloseButton,
			WindowResize		Resize = WindowResize.KeepAspectRatio,
			String				Title = null
			)
        {
            // set media play window code
            MediaScreenParamBE.AddInteger("/W", (Int32) MediaWindow);

            // all choices but floating window
            if(MediaWindow != MediaWindow.Floating)
            {
            MediaScreenParamBE.Remove("/F");
            return;
            }

            // play rendition in floating window
            // Table 9.19 page 774
            PdfDictionary FloatingWindow = new PdfDictionary(this);
            MediaScreenParamBE.AddDictionary("/F", FloatingWindow);

            // window's dimensions
            if(Width == 0 || Height == 0)
            {
            Width = 320;
            Height = 180;
            }
            FloatingWindow.AddFormat("/D", "[{0} {1}]", Width, Height);

            FloatingWindow.AddInteger("/P", (Int32) Position);

            FloatingWindow.AddBoolean("/T", TitleBar != WindowTitleBar.NoTitleBar);
            if(TitleBar == WindowTitleBar.NoTitleBar) return;

            FloatingWindow.AddInteger("/R", (Int32) Resize);

            if(Title != null)
            {
            //			if(Document.Encryption == null)
            //				{
            //				FloatingWindow.AddFormat("/TT", "[() ({0})]", Title);
            //				}
            //			else
            //				{
            FloatingWindow.AddFormat("/TT", "[{0} {1}]", Document.TextToPdfString(String.Empty, this), Document.TextToPdfString(Title, this));
            //				}
            }

            return;
        }
        /// <summary>
        /// Display media constructor
        /// </summary>
        /// <param name="MediaFile">Embedded media file</param>
        /// <param name="MimeType">Mime type</param>
        /// <remarks>
        /// <para>
        /// If mime type is null the program will try to convert file extension
        /// to mime type. If conversion is not available application exception will be raised.
        /// </para>
        /// </remarks>
        public PdfDisplayMedia(
			PdfEmbeddedFile	MediaFile,
			String			MimeType = null
			)
            : base(MediaFile.Document)
        {
            // save media file
            this.MediaFile = MediaFile;

            // save mimetype
            if(MimeType == null) MimeType = MediaFile.MimeType;
            if(String.IsNullOrWhiteSpace(MimeType)) throw new ApplicationException("MIME type is not defined");

            // rendition dictionary page 759 Section 9.1.2 Table 9.1
            Rendition = new PdfDictionary(this);
            Dictionary.AddDictionary("/R", Rendition);

            // media clip
            MediaClip = new PdfDictionary(this);
            Rendition.AddDictionary("/C", MediaClip);

            // Media clip dictionary T 9.9
            TempFilePermissions = new PdfDictionary(this);
            MediaClip.AddDictionary("/P", TempFilePermissions);

            // media play
            MediaPlay = new PdfDictionary(this);
            Rendition.AddDictionary("/P", MediaPlay);

            // media play BE
            MediaPlayBE = new PdfDictionary(this);
            MediaPlay.AddDictionary("/BE", MediaPlayBE);

            // media screen parameters
            MediaScreenParam = new PdfDictionary(this);
            Rendition.AddDictionary("/SP", MediaScreenParam);

            // media screen parameters BE
            MediaScreenParamBE = new PdfDictionary(this);
            MediaScreenParam.AddDictionary("/BE", MediaScreenParamBE);

            // Section 8.5 page 669 table 8.64
            // type of action playing multimedia content
            Dictionary.Add("/S", "/Rendition");

            // media clip data page 762
            Rendition.Add("/S", "/MR");

            // Table 9.6 page 762
            MediaClip.AddPdfString("/CT", MimeType);
            MediaClip.AddIndirectReference("/D", MediaFile);
            MediaClip.Add("/S", "/MCD");
            MediaClip.Add("/Type", "/MediaClip");

            // Operation to perform when action is triggered. Valid options are 0 or 4
            // OP=0 force the Rendition dictionary to take over the annotation
            Dictionary.Add("/OP", "0");

            // allow reader to always create temporary file (other options do not work)
            // Media clip dictionary T 9.10 page 766
            TempFilePermissions.AddPdfString("/TF", "TEMPALWAYS");

            // do not display control
            MediaPlayBE.AddBoolean("/C", false);

            // repeat count of 1
            MediaPlayBE.Add("/RC", "1.0");

            // media scale and position within annotation rectangle PDF default is 5
            // /F=2 strech media to fit annotation
            MediaPlayBE.Add("/F", "2");

            // play rendition in annotation rectangle
            MediaScreenParamBE.Add("/W", "3");

            // exit
            return;
        }
예제 #3
0
        ////////////////////////////////////////////////////////////////////
        // Initial Object Array
        ////////////////////////////////////////////////////////////////////

        private void ConstructorHelper
        (
            double Width,                               // page width
            double Height,                              // page height
            double ScaleFactor,                         // scale factor from user units to points (i.e. 72.0 for inch)
            string FileName,
            Stream OutputStream
        )
        {
            // set scale factor (user units to points)
            this.ScaleFactor = ScaleFactor;

            // set epsilon (1/300 of an inch in user units)
            this.Epsilon = 72.0 / (300.0 * ScaleFactor);

            // save page default size
            PageSize = new SizeD(Width, Height);

            // PDF document root object the Catalog object
            CatalogObject = new PdfObject(this, ObjectType.Dictionary, "/Catalog");

            // add viewer preferences
            CatalogObject.Dictionary.Add("/ViewerPreferences", "<</PrintScaling/None>>");

            // Parent object for all pages
            PagesObject = new PdfObject(this, ObjectType.Dictionary, "/Pages");

            // add indirect reference to pages within the catalog object
            CatalogObject.Dictionary.AddIndirectReference("/Pages", PagesObject);

            // create trailer dictionary
            TrailerDict = new PdfDictionary(this);

            // add /Root
            TrailerDict.AddIndirectReference("/Root", CatalogObject);

            // document id
            DocumentID = RandomByteArray(16);

            // add /ID
            TrailerDict.AddFormat("/ID", "[{0}{0}]", ByteArrayToPdfHexString(DocumentID));

            // create file using file name
            if (FileName != null)
            {
                // save file name
                this.FileName = FileName;

                // constructor helper
                PdfFile = new PdfBinaryWriter(new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None));
            }

            // write to caller's file or memory stream
            else
            {
                PdfFile = new PdfBinaryWriter(OutputStream);
            }

            // write PDF version number
            PdfFile.WriteString("%PDF-1.7\n");

            // add this comment to tell compression programs that this is a binary file
            PdfFile.WriteString("%\u00b5\u00b5\u00b5\u00b5\n");

            // exit
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Add key value pair to dictionary.
        // If dictionary does not exist, create it.
        // If key is not found, add the pair as new entry.
        // If key is found, replace old pair with new one.
        ////////////////////////////////////////////////////////////////////
        internal void AddDictionary(
			String			Key,		// key (first character must be forward slash /)
			PdfDictionary	Value		// value
			)
        {
            Add(Key, Value, ValueType.Dictionary);
            return;
        }
        /// <summary>
        /// Display media constructor
        /// </summary>
        /// <param name="MediaFile">Embedded media file</param>
        /// <param name="MimeType">Mime type</param>
        /// <remarks>
        /// <para>
        /// If mime type is null the program will try to convert file extension
        /// to mime type. If conversion is not available application exception will be raised.
        /// </para>
        /// </remarks>
        public PdfDisplayMedia
        (
            PdfEmbeddedFile MediaFile,
            string MimeType = null
        ) : base(MediaFile.Document)
        {
            // save media file
            this.MediaFile = MediaFile;

            // save mimetype
            if (MimeType == null)
            {
                MimeType = MediaFile.MimeType;
            }
            if (string.IsNullOrWhiteSpace(MimeType))
            {
                throw new ApplicationException("MIME type is not defined");
            }

            // rendition dictionary page 759 Section 9.1.2 Table 9.1
            Rendition = new PdfDictionary(this);
            Dictionary.AddDictionary("/R", Rendition);

            // media clip
            MediaClip = new PdfDictionary(this);
            Rendition.AddDictionary("/C", MediaClip);

            // Media clip dictionary T 9.9
            TempFilePermissions = new PdfDictionary(this);
            MediaClip.AddDictionary("/P", TempFilePermissions);

            // media play
            MediaPlay = new PdfDictionary(this);
            Rendition.AddDictionary("/P", MediaPlay);

            // media play BE
            MediaPlayBE = new PdfDictionary(this);
            MediaPlay.AddDictionary("/BE", MediaPlayBE);

            // media screen parameters
            MediaScreenParam = new PdfDictionary(this);
            Rendition.AddDictionary("/SP", MediaScreenParam);

            // media screen parameters BE
            MediaScreenParamBE = new PdfDictionary(this);
            MediaScreenParam.AddDictionary("/BE", MediaScreenParamBE);

            // Section 8.5 page 669 table 8.64
            // type of action playing multimedia content
            Dictionary.Add("/S", "/Rendition");

            // media clip data page 762
            Rendition.Add("/S", "/MR");

            // Table 9.6 page 762
            MediaClip.AddPdfString("/CT", MimeType);
            MediaClip.AddIndirectReference("/D", MediaFile);
            MediaClip.Add("/S", "/MCD");
            MediaClip.Add("/Type", "/MediaClip");

            // Operation to perform when action is triggered. Valid options are 0 or 4
            // OP=0 force the Rendition dictionary to take over the annotation
            Dictionary.Add("/OP", "0");

            // allow reader to always create temporary file (other options do not work)
            // Media clip dictionary T 9.10 page 766
            TempFilePermissions.AddPdfString("/TF", "TEMPALWAYS");

            // do not display control
            MediaPlayBE.AddBoolean("/C", false);

            // repeat count of 1
            MediaPlayBE.Add("/RC", "1.0");

            // media scale and position within annotation rectangle PDF default is 5
            // /F=2 strech media to fit annotation
            MediaPlayBE.Add("/F", "2");

            // play rendition in annotation rectangle
            MediaScreenParamBE.Add("/W", "3");

            // exit
            return;
        }