我正在使用类似下面的代码成功地提取PDF包文件的内容:
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‘属性?
发布于 2017-02-07 02:56:30
"Index“属性可以是也可以不是文件夹所排序的实际元数据片段。项目组合可以在任意数量的集合字段上进行排序,包括隐藏字段。要找到实际的排序顺序,您需要从"Catalog“中的"Collection”字典中获取" sort“字典。完成后,您可以根据每个附件中的"CI“(集合信息)字典对文件进行排序。
我会抛出一些代码给你,但我不使用iText...不管是不是很锋利。
https://stackoverflow.com/questions/42074324
复制相似问题