我正在使用石英来显示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
对象数组。
答案 0 :(得分:6)
这样的事情可能会帮助你开始:
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
}
}
答案 1 :(得分:4)
这是我的方法。
1。下载此框架vfr reader
2。使用这行代码获取所有PDF章节
NSString *path = [[NSBundle mainBundle] pathForResource:@"Reader" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSArray *arr = [ReaderDocumentOutline outlineFromFileURL:targetURL password:@""];
希望它会对你有所帮助。
答案 2 :(得分:0)
我使用iOS FastPdfKit
答案 3 :(得分:0)
您可以使用PDFKit的PDFOutline对象创建目录(AKA大纲,书签)。您还可以阅读PDF中的现有大纲。
CGPDFDocumentGetCatalog
是一种用于获取文件中PDF数据目录的方法,该目录的级别比人类对“内容”的概念要低得多。
在没有现有大纲的情况下,我不确定是否有办法从PDF流本身获取有意义的数据,例如试图仅从PDF数据中提取章节标题。