首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PDF包文件中嵌入文件的顺序?

PDF包文件中嵌入文件的顺序?
EN

Stack Overflow用户
提问于 2017-02-07 02:01:23
回答 1查看 455关注 0票数 0

我正在使用类似下面的代码成功地提取PDF包文件的内容:

代码语言:javascript
复制
internal void ExtractAttachments(string file_name, string folderName) {
    PdfDictionary documentNames = null;
    PdfDictionary embeddedFiles = null;
    PdfDictionary fileArray = null;
    PdfDictionary file = null;
    PRStream stream = null;

    using (PdfReader reader = new PdfReader(file_name)) {
        PdfDictionary catalog = reader.Catalog;

        documentNames = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.NAMES));

        if (documentNames != null) {
            embeddedFiles = (PdfDictionary)PdfReader.GetPdfObject(documentNames.Get(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));
                        string attachedFileName = fileArray.GetAsString(key).ToString();
                        byte[] attachedFileBytes = PdfReader.GetStreamBytes(stream);

                        System.IO.File.WriteAllBytes(Path.Combine(folderName, attachedFileName), attachedFileBytes);
                    }
                }
            }
        }
    }
}

但是,我注意到这些组件文件的提取顺序与使用Adobe Reader XI在原始PDF中显示的顺序不同。这些组件文件的显示顺序显然是在"Index“属性中给出的,您可以在Reader UI中显示该属性,方法是选择以文件模式(而不是布局模式)查看项目组合文件,右键单击任何组件文件,然后从上下文菜单中选择”view“>”Index“。

我的问题是:在从PDF包文件中提取文件之前,如何找到这个'index‘属性?

EN

回答 1

Stack Overflow用户

发布于 2017-02-07 02:56:30

"Index“属性可以是也可以不是文件夹所排序的实际元数据片段。项目组合可以在任意数量的集合字段上进行排序,包括隐藏字段。要找到实际的排序顺序,您需要从"Catalog“中的"Collection”字典中获取" sort“字典。完成后,您可以根据每个附件中的"CI“(集合信息)字典对文件进行排序。

我会抛出一些代码给你,但我不使用iText...不管是不是很锋利。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42074324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档