How to iterate over CGPDFDictionary using Monotouch?
I'm using this code to get the contents of a PDF:
var oDoc = new CGPDFDocument.FromFile("./test.pdf");
var oCat = oDoc.GetCatalog();
But how do I know iterate the catalog? All methods want a "key" but I don't know how to get the root key or the array of keys.
I found that in ObjC one would use something like:
CGPDFDictionaryApplyFunction(pdfDocDictionary, ListDictionaryObjects, NULL);
void ListDictionaryObjects (const char *key, CGPDFObjectRef object, void *info) {
NSLog("key: %s", key);
CGPDFObjectType type = CGPDFObjectGetType(object);
switch (type) {
case kCGPDFObjectTypeDictionary: {
CGPDFDictionaryRef objectDictionary;
if (CGPDFObjectGetValue(object, kCGPDFObjectTypeDictionary, &objectDictionary)) {
CGPDFDictionaryApplyFunction(objectDictionary, ListDictionaryObjects, NULL);
}
}
case kCGPDFObjectTypeInteger: {
CGPDFInteger objectInteger;
if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInt开发者_如何学Ceger)) {
NSLog("pdf integer value: %ld", (long int)objectInteger);
}
}
// test other object type cases here
// cf. http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGPDFObject/Reference/reference.html#//apple_ref/doc/uid/TP30001117-CH3g-SW1
}
}
See also: What is the equivalent of CGPDFDocumentGetCatalog in Monotouch?
It looks like MonoTouch (and MonoMac since this is shared code) are missing the binding for CGPDFDictionaryApplyFunction too. Without it you need to know the key values that are in the dictionary.
That works well if you're looking for something specific (i.e. a well-known key value) but not if you want to inspect/show everything that exists inside a dictionary instance.
I'll look to add this binding into 'maccore' (consumed by both MonoMac and MonoTouch) and will update this entry with the binding so it can be used inside application (until fixed versions are available).
精彩评论