2012-01-06 77 views
1

我已經創建了一個PDF閱讀器,現在我想要顯示目錄就像索引,我想從該表中獲取所有頁面是否有任何方式或方法來做到這一點?PDF閱讀器中的目錄

-Thanx任何提前

回答

0

雖然這是很老的文章,認爲ü可能已經解決了這個問題,我米張貼這個答案,讓其他人能有解決方案。

此功能不完整,但可以很好的開始。 :)

CGPDFDocumentGetCatalog功能可幫助您獲得目錄

CGPDFDictionaryRef oldDict = CGPDFDocumentGetCatalog(pdf); 
CGPDFDictionaryApplyFunction(oldDict, copyDictionaryValues, NULL); 


void copyDictionaryValues (const char *key, CGPDFObjectRef object, void *info) { 
    // NSLog(@"key: %s", key); 
CGPDFObjectType typeObj = CGPDFObjectGetType(object); 
switch (typeObj) { 
    case kCGPDFObjectTypeDictionary: { 
     CGPDFDictionaryRef objectDictionary; 
     if (CGPDFObjectGetValue(object, kCGPDFObjectTypeDictionary, &objectDictionary)) { 
      CGPDFDictionaryApplyFunction(objectDictionary, copyDictionaryValues, NULL); 
     } 
    } 
     break; 
    case kCGPDFObjectTypeString: { 
     CGPDFStringRef objectString; 
     if (CGPDFObjectGetValue(object, kCGPDFObjectTypeString, &objectString)) { 
      NSString *tempStr = (NSString *)CGPDFStringCopyTextString(objectString); 
      [auxInfo setObject:tempStr 
            forKey:[NSString stringWithCString:key encoding:NSUTF8StringEncoding]]; 
      [tempStr release]; 
     // NSLog(@"set string value"); 
     } 
    } 
     break; 
    case kCGPDFObjectTypeInteger: { 
     CGPDFInteger objectInteger; 
     if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInteger)) { 
      [auxInfo setObject:[NSNumber numberWithInt:objectInteger] 
            forKey:[NSString stringWithCString:key encoding:NSUTF8StringEncoding]]; 
     //  NSLog(@"set int value"); 
     } 
    } 
     break; 
    case kCGPDFObjectTypeBoolean: { 
     CGPDFBoolean objectBool; 
     if (CGPDFObjectGetValue(object, kCGPDFObjectTypeBoolean, &objectBool)) { 
      [auxInfo setObject:[NSNumber numberWithBool:objectBool] 
            forKey:[NSString stringWithCString:key encoding:NSUTF8StringEncoding]]; 
     //  NSLog(@"set boolean value"); 
     } 
    } 
     break; 
    case kCGPDFObjectTypeArray : { 
     CGPDFArrayRef objectArray; 
     if (CGPDFObjectGetValue(object, kCGPDFObjectTypeArray, &objectArray)) { 
     // copyPDFArray(objectArray); 

      NSLog(@"set array value"); 
     } 
    } 

} 
}