我正在使用quartz来显示pdf内容,我需要创建一个目录来浏览pdf.从阅读Apple的文档我认为我应该使用CGPDFDocumentGetCatalog,但我找不到任何关于如何在任何地方使用它的例子.有任何想法吗?
更新:仍未找到解决方案.我厌倦了Alex的解决方案,但我得到的输出看起来像这样:
2011-07-27 09:16:19.359 LDS Scriptures App-iPad[624:707] key: Pages 2011-07-27 09:16:19.361 LDS Scriptures App-iPad[624:707] key: Count 2011-07-27 09:16:19.362 LDS Scriptures App-iPad[624:707] pdf integer value: 238 2011-07-27 09:16:19.363 LDS Scriptures App-iPad[624:707] key: Kids 2011-07-27 09:16:19.366 LDS Scriptures App-iPad[624:707] key: Type 2011-07-27 09:16:19.368 LDS Scriptures App-iPad[624:707] key: Outlines 2011-07-27 09:16:19.370 LDS Scriptures App-iPad[624:707] key: Count 2011-07-27 09:16:19.371 LDS Scriptures App-iPad[624:707] pdf integer value: 7 2011-07-27 09:16:19.372 LDS Scriptures App-iPad[624:707] key: First 2011-07-27 09:16:19.374 LDS Scriptures App-iPad[624:707] key: Parent 2011-07-27 09:16:19.375 LDS Scriptures App-iPad[624:707] key: Count 2011-07-27 09:16:19.376 LDS Scriptures App-iPad[624:707] pdf integer value: 7
不知道如何将其转换为可用的目录.理想情况下,我想获得一个NSDictionary
带有标题和匹配页码的对象数组.
这样的事情可能会帮助你开始:
NSURL *documentURL = ...; // URL to file or http resource etc. CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithURL((CFURLRef)documentURL); CGPDFDictionaryRef pdfDocDictionary = CGPDFDocumentGetCatalog(pdfDocument); // loop through dictionary... CGPDFDictionaryApplyFunction(pdfDocDictionary, ListDictionaryObjects, NULL); CGPDFDocumentRelease(pdfDocument); ... void ListDictionaryObjects (const char *key, CGPDFObjectRef object, void *info) { NSLog("key: %s", key); CGPDFObjectType type = CGPDFObjectGetType(object); switch (type) { case kCGPDFObjectTypeDictionary: { CGPDFDictionaryRef objectDictionary; if (CGPDFObjectGetValue(object, kCGPDFObjectTypeDictionary, &objectDictionary)) { CGPDFDictionaryApplyFunction(objectDictionary, ListDictionaryObjects, NULL); } } case kCGPDFObjectTypeInteger: { CGPDFInteger objectInteger; if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInteger)) { NSLog("pdf integer value: %ld", (long int)objectInteger); } } // test other object type cases here // cf. http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGPDFObject/Reference/reference.html#//apple_ref/doc/uid/TP30001117-CH3g-SW1 } }