1
任何人成功嘗試使用iPhone API讀取PDF文檔的目錄詞典?我沒有得到任何有意義的東西:目錄中的大多數字典都是空的。使用iPhone SDK閱讀PDF文檔時出現問題?
任何人成功嘗試使用iPhone API讀取PDF文檔的目錄詞典?我沒有得到任何有意義的東西:目錄中的大多數字典都是空的。使用iPhone SDK閱讀PDF文檔時出現問題?
試試這個:
CGPDFDictionaryRef catalog = CGPDFDocumentGetCatalog(myDocument);
CGPDFDictionaryApplyFunction(catalog, streamInfoFunction, catalog);
的目錄基本上是一本字典,你有你使用就可以了施放功能,如圖所示。
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?