2010-04-07 3 views
1

누구나 succesfull이 iPhone API를 사용하여 PDF 문서의 카탈로그 사전을 읽으려고 했습니까? 나는 이해할 수있는 어떤 것도 얻지 못한다. 카탈로그 안에있는 대부분의 사전은 비어있다.iPhone SDK를 사용하여 PDF 문서를 읽는 데 문제가 있습니까?

CGPDFDictionaryRef catalog = CGPDFDocumentGetCatalog(myDocument); 
CGPDFDictionaryApplyFunction(catalog, streamInfoFunction, catalog); 

카탈로그 기본적으로 사전이고 당신은 같이 당신이 그것에 적용자 기능을 사용할 수 있습니다

답변

3

이보십시오.

void streamInfoFunction (const char *key,CGPDFObjectRef object, void *info) 
{ 
NSLog(@"---------------------------------------------------------------------------------------------"); 
NSLog(@"Processing Stream Info"); 

NSString *keyStr = [NSString stringWithCString:key encoding:NSUTF8StringEncoding]; 
CGPDFDictionaryRef contentDict = (CGPDFDictionaryRef)info; 

CGPDFObjectType objectType = CGPDFObjectGetType(object); 
if(objectType == kCGPDFObjectTypeDictionary) 
{ 
    CGPDFDictionaryRef value = NULL; 
    CGPDFDictionaryGetDictionary(contentDict, key, &value); 
    NSLog(@"Value for key %@ is %d",keyStr,CGPDFDictionaryGetCount(value)); 
     //S.SNSLog(@"%@",value); 
} 
else if(objectType == kCGPDFObjectTypeArray) 
{ 
    CGPDFArrayRef value = NULL; 
    CGPDFDictionaryGetArray(contentDict, key, &value); 
    NSLog(@"Value for key %@ is %d",keyStr,CGPDFArrayGetCount(value)); 
     //S.SNSLog(@"%@",value); 
} 
else if(objectType == kCGPDFObjectTypeStream) 
{ 
    CGPDFStreamRef value = NULL; 
    CGPDFDictionaryGetStream(contentDict, key, &value); 
    NSLog(@"Processing for key %@",keyStr); 
    CGPDFDataFormat dataFormat; 
    CFDataRef streamData = CGPDFStreamCopyData(value, &dataFormat); 
    CFShow(streamData); 
    NSString *contentString = [[NSString alloc]initWithBytes:[(NSData*)streamData bytes] length:[(NSData*)streamData length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@",contentString); 

} 
else if(objectType == kCGPDFObjectTypeInteger) 
{ 
    CGPDFInteger integerValue; 
    CGPDFDictionaryGetInteger(contentDict, key, &integerValue); 
    NSLog(@"Processing for Key %@ value %d",keyStr,integerValue); 

} 
else if(objectType == kCGPDFObjectTypeName) 
{ 
    const char *name; 
    CGPDFDictionaryGetName(contentDict, key, &name); 
    NSLog(@"Processing for key %@ value %s",keyStr,[NSString stringWithCString:name encoding:NSUTF8StringEncoding]); 
} 

NSLog(@"---------------------------------------------------------------------------------------------"); 

} 

일반적인 참고 참조 : Fast and Lean PDF Viewer for iPhone/iPad/iOs - tips and hints?

관련 문제