File information is missing from an embedded file. How do I add it using the SDK?

Q: When using the FileSpec API to embed a file, the file size and modification date information is missing when viewing a file in Adobe Reader. How do I add this information?

A: The info is part of the optional parameters within the FileSpec object. You can use the following code to add it to the PDF, where fs is the FileSpec object that was created:

var ef_obj = fs.GetSDFObj().FindObj("EF");
if (ef_obj != null && ef_obj.IsDict())
{
    var ef = ef_obj.FindObj("F");
    if (ef != null && ef.IsStream())
    {
        var param = ef.FindObj("Params");
        if (param == null)
        {
            param = ef.PutDict("Params");
        }

        byte[] date = System.Text.Encoding.UTF8.GetBytes(String.Format("D:{0}{1}{2}{3}{4}{5}", YEAR, MONTH, DD, HH, MM, SS));
        // optionally, you can also include the UTC offset. below example is -7:00 (pacific daylight time) 
        byte[] date = System.Text.Encoding.UTF8.GetBytes(String.Format("D:{0}{1}{2}{3}{4}{5}-{6}'{7}'", YEAR, MONTH, DD, HH, MM, SS, 07, 00));
        param.PutString("CreationDate", date); // date created
        param.PutString("ModDate", date); // modified last date
        param.PutNumber("Size", 432444); // file size
    }
}