Created
November 23, 2011 21:23
-
-
Save amarcadet/1389966 to your computer and use it in GitHub Desktop.
Enumerates a CGPDFDictionaryRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void enumeratesDictionaryValues(const char *key, CGPDFObjectRef object, void *info) | |
| { | |
| NSLog(@"---------- key ------ %s ---------------", key); | |
| CGPDFObjectType type = CGPDFObjectGetType(object); | |
| switch (type) | |
| { | |
| case kCGPDFObjectTypeString: | |
| { | |
| CGPDFStringRef objectString; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeString, &objectString)) | |
| { | |
| NSString *tempStr = (NSString *)CGPDFStringCopyTextString(objectString); | |
| NSLog(@"(string) %s = %@", key, tempStr); | |
| [tempStr release]; | |
| } | |
| } | |
| case kCGPDFObjectTypeInteger: | |
| { | |
| CGPDFInteger objectInteger; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInteger)) | |
| { | |
| NSLog(@"(int) %s = %ld", key, objectInteger); | |
| } | |
| } | |
| case kCGPDFObjectTypeBoolean: | |
| { | |
| CGPDFBoolean objectBool; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeBoolean, &objectBool)) | |
| { | |
| NSLog(@"(boolean) %s = %d", key, objectBool); | |
| } | |
| } | |
| case kCGPDFObjectTypeArray: | |
| { | |
| CGPDFArrayRef objectArray; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeArray, &objectArray)) | |
| { | |
| enumeratesArrayValues(objectArray); | |
| } | |
| } | |
| } | |
| } | |
| void enumeratesArrayValues(CGPDFArrayRef arr) | |
| { | |
| for (int i = 0; i < CGPDFArrayGetCount(arr); i++) | |
| { | |
| CGPDFObjectRef object; | |
| CGPDFArrayGetObject(arr, i, &object); | |
| CGPDFObjectType type = CGPDFObjectGetType(object); | |
| switch (type) | |
| { | |
| case kCGPDFObjectTypeString: | |
| { | |
| CGPDFStringRef objectString; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeString, &objectString)) | |
| { | |
| NSString *tempStr = (NSString *)CGPDFStringCopyTextString(objectString); | |
| NSLog(@"(string) = %@", tempStr); | |
| [tempStr release]; | |
| } | |
| } | |
| case kCGPDFObjectTypeInteger: | |
| { | |
| CGPDFInteger objectInteger; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInteger)) | |
| { | |
| NSLog(@"(int) = %ld", objectInteger); | |
| } | |
| } | |
| case kCGPDFObjectTypeBoolean: | |
| { | |
| CGPDFBoolean objectBool; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeBoolean, &objectBool)) | |
| { | |
| NSLog(@"(boolean) = %d", objectBool); | |
| } | |
| } | |
| case kCGPDFObjectTypeArray: | |
| { | |
| CGPDFArrayRef objectArray; | |
| if (CGPDFObjectGetValue(object, kCGPDFObjectTypeArray, &objectArray)) | |
| { | |
| enumeratesArrayValues(objectArray); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| CGPDFDictionaryApplyFunction(CGPDFDocumentGetInfo(pdfRef), enumeratesDictionaryValues, NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we have this for Swift?