How can I get file attachments that are present in any existing PDF files?

Q: How can I get the attachment collection already present in any
existing pdf file and access individual attachments

The file attachment annotations can be accessed via Annot class
interface (see Annotation sample project for more info).

File attachments that are not associated with any document can be
accessed by searching document object index. For example:

Doc cos_doc = doc.GetSDFDoc();
int num_objs = cos_doc.XRefSize();
for (int i=1; i<num_objs; ++i) {
  Obj obj = cos_doc.GetObj(i);
  if (obj!=null && !obj.IsFree()&& obj.IsDict()) {
    // Process only Filespec objects
    DictIterator itr = obj.Find("Type");
    if (itr == obj.DictEnd() || itr.Value().GetName() != "Filespec")

   // .. Process obj Filespec low level object
   Filespec fs = new Filespec(obj);

Alternatively you can also traverse all FileSpec listed under
"EmbeddedFiles" name tree. Somethiong along the following lines:

SDF.NameTree names = SDF.NameTree.Find(doc, "EmbeddedFiles");
if(!names.IsValid()) return;

// Traversing the NameTree
NameTreeIterator end = names.End();
NameTreeIterator i = names.Begin();
for (; i!=end; ++i) {
  Obj spec = i->Value();
  Filespec fs = new Filespec(spec);