Hi All,

 

I have tried to extract attachment from pdf and it throws null for the
attached pdf. This happens only for Acrobat Distiller profile and no
issue in other file types.

 

Here is the code I have tried to extract attachment.

 

private List<FileContent> GetAttachments(PdfReader reader)

        {

            #region Variables

 

            PdfDictionary catalog = null;

            PdfDictionary documentNames = null;

            PdfDictionary embeddedFiles = null;

            PdfDictionary fileArray = null;

            PdfDictionary file = null;

 

            PRStream stream = null;

 

            FileContent fContent = null;

            List<FileContent> lstAtt = null;

 

            #endregion

 

            catalog = reader.Catalog;                        

            lstAtt = new List<FileContent>();

            documentNames = catalog.GetAsDict(PdfName.NAMES);

            if (documentNames != null)

            {

                embeddedFiles =
documentNames.GetAsDict(PdfName.EMBEDDEDFILES);

                if (embeddedFiles != null)

                {                    

                    PdfArray filespecs =
embeddedFiles.GetAsArray(PdfName.NAMES);

                    for (int i = 0; i < filespecs.Size; i++)

                    {                        

                        i++;

                        fileArray = filespecs.GetAsDict(i);


                        file = fileArray.GetAsDict(PdfName.EF);

                        foreach (PdfName key in file.Keys)

                        {

                            stream =
(PRStream)PdfReader.GetPdfObject(file.GetAsIndirectObject(key));

                            fContent = new FileContent();

                            fContent.Name =
fileArray.GetAsString(key).ToString();

                            fContent.Content =
PdfReader.GetStreamBytes(stream);

                            lstAtt.Add(fContent);

                        }

                    }

                }

            }

            return lstAtt;

        }

 

Can anyone help to solve this issue?

 

Regards,

Selvakumar

Attachment: Sample1.pdf
Description: Sample1.pdf

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to