簡體   English   中英

使用iPhone SDK讀取PDF文檔時遇到問題?

[英]Problems reading PDF document using iPhone SDK?

任何人成功嘗試使用iPhone API讀取PDF文檔的目錄字典嗎? 我沒有得到任何有意義的信息:目錄中的大多數詞典都是空的。

嘗試這個:

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

Catalog基本上是一本字典,您可以在其上使用如圖所示的applier函數。

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(@"---------------------------------------------------------------------------------------------");

}

有關一般參考,請參閱: 適用於iPhone / iPad / iO的Fast and Lean PDF Viewer-提示和提示?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM