namespace PdfSharpCore.Pdf.Advanced { /// /// Represent a file stream embedded in the PDF document /// public class PdfEmbeddedFile : PdfDictionary { private readonly PdfDictionary paramsDictionary; public PdfEmbeddedFile(PdfDocument document) : base(document) { this.paramsDictionary = new PdfDictionary(); Elements.SetName(Keys.Type, "/EmbeddedFile"); Elements.SetObject(Keys.Params, paramsDictionary); } public PdfEmbeddedFile(PdfDocument document, byte[] bytes, string checksum = null) : this(document) { this.CreateStreamAndSetProperties(bytes, checksum); } public void CreateStreamAndSetProperties(byte[] bytes, string checksum = null) { this.CreateStream(bytes); this.paramsDictionary.Elements.SetInteger(Keys.Size, bytes.Length); if (string.IsNullOrEmpty(checksum)) this.paramsDictionary.Elements.Remove(Keys.CheckSum); else this.paramsDictionary.Elements.SetString(Keys.CheckSum, checksum); } public string MimeType { get { return Elements.GetName(Keys.Subtype); } set { Elements.SetName(Keys.Subtype, value); } } // TODO : Add properties for the subdictionnary Params and the subsubdictionnary Mac /// /// Predefined keys of this embedded file. /// public class Keys : PdfDictionary.PdfStream.Keys { /// /// (Optional) The type of PDF object that this dictionary describes; if present, /// must be EmbeddedFile for an embedded file stream. /// [KeyInfo(KeyType.Name | KeyType.Optional, FixedValue = "EmbeddedFile")] public const string Type = "/Type"; /// /// (Optional) The subtype of the embedded file. The value of this entry must be a /// first-class name, as defined in Appendix E. Names without a registered prefix /// must conform to the MIME media type names defined in Internet RFC 2046, /// Multipurpose Internet Mail Extensions (MIME), Part Two: Media Types(see the /// Bibliography), with the provision that characters not allowed in names must /// use the 2-character hexadecimal code format described in Section 3.2.4, /// “Name Objects.” /// [KeyInfo(KeyType.Name | KeyType.Optional)] public const string Subtype = "/Subtype"; /// /// (Optional) An embedded file parameter dictionary containing additional, /// file-specific information (see Table 3.43). /// [KeyInfo(KeyType.Dictionary | KeyType.Optional)] public const string Params = "/Params"; /// /// (Optional) The size of the embedded file, in bytes. /// [KeyInfo(KeyType.Integer | KeyType.Optional)] public const string Size = "/Size"; /// /// (Optional) The date and time when the embedded file was created. /// [KeyInfo(KeyType.Date | KeyType.Optional)] public const string CreationDate = "/CreationDate"; /// /// (Optional) The date and time when the embedded file was last modified. /// [KeyInfo(KeyType.Date | KeyType.Optional)] public const string ModDate = "/ModDate"; /// /// (Optional) A subdictionary containing additional information specific to Mac OS files (see Table 3.44). /// [KeyInfo(KeyType.Dictionary | KeyType.Optional)] public const string Mac = "/Mac"; /// /// (Optional) A 16-byte string that is the checksum of the bytes of the uncompressed /// embedded file. The checksum is calculated by applying the standard MD5 message-digest /// algorithm (described in Internet RFC 1321, The MD5 Message-Digest Algorithm; see the /// Bibliography) to the bytes of the embedded file stream. /// [KeyInfo(KeyType.Dictionary | KeyType.Optional)] public const string CheckSum = "/CheckSum"; /// /// Gets the KeysMeta for these keys. /// internal static DictionaryMeta Meta { get { if (Keys.meta == null) Keys.meta = CreateMeta(typeof(Keys)); return Keys.meta; } } static DictionaryMeta meta; } /// /// Gets the KeysMeta of this dictionary type. /// internal override DictionaryMeta Meta { get { return Keys.Meta; } } } }