PdfRpt.Core.Helper.ExtractPdfFileAttachments.extractFile C# (CSharp) Method

extractFile() private static method

private static extractFile ( PdfDictionary filespec ) : PdfRpt.Core.Contracts.AttachmentFile
filespec iTextSharp.text.pdf.PdfDictionary
return PdfRpt.Core.Contracts.AttachmentFile
        private static AttachmentFile extractFile(PdfDictionary filespec)
        {
            if (filespec == null)
                return null;

            var type = PdfReader.GetPdfObject(filespec.Get(PdfName.TYPE)) as PdfName;
            if (!PdfName.F.Equals(type) && !PdfName.FILESPEC.Equals(type))
                return null;

            var ef = PdfReader.GetPdfObject(filespec.Get(PdfName.EF)) as PdfDictionary;
            if (ef == null)
                return null;

            var fn = PdfReader.GetPdfObject(filespec.Get(PdfName.F)) as PdfString;
            if (fn == null)
                return null;

            var prs = PdfReader.GetPdfObject(ef.Get(PdfName.F)) as PRStream;
            if (prs == null)
                return null;

            return new AttachmentFile
            {
                Content = PdfReader.GetStreamBytes(prs),
                FileName = fn.ToUnicodeString()
            };
        }