//////////////////////////////////////////////////////////////////// // 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) 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 }
/// <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; }
/// <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; }