我创建了一个pdf查看器现在我想显示目录就像索引一样,我想从该表中获取所有页面有没有任何方法或方法可以做到这一点?
-Thanx任何提前
答案 0 :(得分: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");
}
}
}
}